nhibernate

How do I save a transient object that already exists in an NHibernate session?

I have a Store that contains a list of Products: var store = new Store(); store.Products.Add(new Product{ Id = 1, Name = "Apples" }; store.Products.Add(new Product{ Id = 2, Name = "Oranges" }; Database.Save(store); Now, I want to edit one of the Products, but with a transient entity. This will be, for example, data from a web browser...

In NHIbernate, why does SaveOrUpdate() update the Version, but SaveOrUpdateCopy() doesn't?

I have a versioned entity, and this is what happens when I use SaveOrUpdate() vs. SaveOrUpdateCopy(): // create new entity var entity = new Entity{ Id = Guid.Empty }); Console.WriteLine(entity.Version); // prints out 0 // save the new entity GetNewSession(); entity.SaveOrUpdate(); Console.WriteLine(entity.Version); // prints out 1 Get...

Implementing auto-save in WPF / MVVM / NHibernate

My client likes programs like Microsoft OneNote where changes are saved automatically, and he can choose to discard when he explicitly wants to do so. I will have to implement some undo functionality, but I'll figure that out some other time. With NHibernate, I suppose I can call ISession.Update on every single property / binding change...

Fluent NHibernate SqlDateTime overflow exception

Hey, I'm mapping a very simple Users table, and i have a column named 'LastLoginDate' which is defined as nullable in sql server. My mapping looks like this : public Users { Id(x => x.UserId); Map(x => x.UserName); ... ... Map(x => x.LastLoginDate).Nullable(); } But everytime I try to save this entity programatic...

Which version of MySql.data.dll should I use with NHibernate 2.1.2.4000

Hi, Which version of MySql.data.dll should I use with NHibernate 2.1.2.4000?? This is also with the latest version of Fluent NH. Thank you ...

Which ORM to use?

I'm developing an application which will have these classes: class Shortcut { public string Name { get; } public IList<Trigger> Triggers { get; } public IList<Action> Actions { get; } } class Trigger { public string Name { get; } } class Action { public string Name { get; } } And I will have 20+ more classes, whi...

nhibernate, Retrieve the latest row in a table

A user can have many addresses, but I want to retrieve the latest entry for the user. In sql I would do: SELECT TOP 1 * FROM UserAddress WHERE userID = @userID How can I create a criteria query with the same logic? Is there a TOP functionality? ...

How to do a NotEqual to in NHibernate

I have an enumeration of type int in my entity, UserStatus. I want to get all users where the UserStatus <> Cancelled. So: Session.CreateCriteria(typeof(User)) .Add(Expression.Eq("UserStatus", (int)UserStatus.Cancelled) .UniqueResult<User>(); The above is fore equal, I need to get not equal. ...

NHibernate / multiple sessions and nested objects

We are using NHibernate in a rich client application. It is a pretty open application (the user searches for a dataset or creates a new one, changes the data and saves the data set. We leave the session open, because sometimes we have to lazy load some properties of the object (nested object structure). This means one big problem if w...

How to fine tune FluentNHibernate's auto mapper?

Okay, so yesterday I managed to get the latest trunk builds of NHibernate and FluentNHibernate to work with my latest little project. (I'm working on a bug tracking application.) I created a nice data access layer using the Repository pattern. I decided that my entities are nothing special, and also that with the current maturity of ORM...

Nhibernate HQL Subselect queries

Hi I have the following SQL query: select c.id from (select id from customers) c This query has no practical value - I simplified it greatly for the purpose of this post. My question: is it possible have a subquery in the from clause using HQL. If not, can I perhaps query the customers first, kinda like a temp table in sql, and then...

NHibernate: Many-to-many relationship with field in the relationship table

I'm scratching my head; I have a Car table and a Customer table that have a many-to-many relationship. In this relationship table I want to add a column that can tell me what kind of relationship this is; is the customer testdriving the car, do he want to buy the car, ect. What I want to end up with is a class Car object that holds a col...

best strategy for human readable id within nhibernate

What would be the best way to achieve a human readable number, currently have Identity set to a surrogate key. have been thinking of identity seed but this would lead to gaps. If i were to generate within a transaction scope then, would concurrency have an effect ? Would prefer to avoid DBCC CHECKIDENT trigger. thanks. ...

Many To Many NHibernate

Hello guys. I'm having some problems with NHibernate when it comes to mapping many to many relationships, specially this one. I have a Category table, which each parent can have as many childs as it needs, and it can be also a parent. When i try to select something from category table, i get an error: ERROR: 42601: syntax error at or ...

Nhibernate: building a List<string> through <component>

If I have a field in the db which stores a set of comma separated strings (says tags), how can I instruct fluent Nhibernate to pick it up at List<string>() e.g. Public IList<string> Tags {get; set;} Db field values: Mvc, .net, FNH ...

NHibernate - Log items that appear in a search result

I am using NHibernate in an MVC 2.0 application. Essentially I want to keep track of the number of times each product shows up in a search result. For example, when somebody searches for a widget the product named WidgetA will show up in the first page of the search results. At this point i will increment a field in the database to refl...

Mixing inheritance mapping strategies in NHibernate

I have a rather large inheritance hierarchy in which some of the subclasses add very little and others add quite a bit. I don't want to map the entire hierarchy using either "table per class hierarchy" or "table per subclass" due to the size and complexity of the hierarchy. Ideally I'd like to mix mapping strategies such that portions ...

Fluent NHibernate Repository with subclasses

Having some difficulty understanding the best way to implement subclasses with a generic repository using Fluent NHibernate. I have a base class and two subclasses, say: public abstract class Person { public virtual int PersonId { get; set; } public virtual string FirstName { get; set; } public virtual string LastName { get...

Is this a right way to use NHibernate?

I spent the rest of the evening reading StackOverflow questions and also some blog entries and links about the subject. All of them turned out to be very helpful, but I still feel that they don't really answer my question. So, I'm developing a simple web application. I'd like to create a reusable data access layer which I can later reus...

Castle ActiveRecord optimistic locking on properties

Can Castle ActiveRecord do optimistic locking on properties? I found optimistic locking for the entire class, but not for an individual property. In my case, I need to make it so that adding/removing elements in a collection does not update the version number of the entity (so for example, adding a Product to a Store without changing any...