nhibernate

Fluent NH - illegal access to loading collection

In the CategoriesTranslated collection i have this error: illegal access to loading collection. public class Category : Entity { public Category() { CategoriesTranslated = new List<CategoryTranslated>(); } public virtual Category Parent { get; set; } public virtual string Name { get; set; } public virt...

Deciding between NHibernate vs Entity Framework?

What are the main advantages and disadvantages of NHibernate and Entity Framework 4.0? (While tagging my question, I've noticed more NHibernate tags than EF. Is NHibernate more popular?) ...

NHibernate query - Many-to-Many - eager loading (twitter style followers/following)

I have come stuck in optimizing one of my queries...here is my scenario... I have a domain simular to Twitter where a user can follow other users. So here is a sample of my User model: User -> Followers (many-to-many users) -> Following (many-to-many users) I now need to return a paged result of users following user 'XYZ', but also...

How to have manage sub Transactions or nested transactions?

I want to have something like sub-transactions, in that you can mark a point where you would start the sub-transaction, then at the point of descision for that bit, you can either roll-back (abort the sub-bit) or carry on, effectively commiting, when the out transation commits. Of course, if you abort the outer transaction, the marked bi...

How do I take the "top n" using NHibernate Criteria API?

How do I take the "top n" using NHibernate Criteria API? Ideally I'd like to use detached criteria. ...

Nhibernate custom loader for collection

Im really hoping someone can help with this, have been trying various combinations for a day and a half now.... Basically I have a some hierarchical data stored in a single table, the usual parentID maps to a row id scenario. I have modelled a property within the domain object that returns a list of ancestors for a given item. It all s...

How to quote Fieldnames in Fluent NHibernate 1.1

After upgrading from Fluent NHibernate 1.0 RTM to 1.1 I got some strange errors when creating the database. After some investigation I discovered that FNH 1.0 quoted all field names in the generated mapping files like 'user', but FNH 1.1 did not. This results in errors for the generated sql script when I use restriced keywords for proper...

Nhibernate Linq 3 In Clause

It seems that a In clause is not working properly with Linq 3.0 (trunk) I tried following: var l = session.Query.Where(p => searchGroups.Contains(p.ID)).Select(r=>r); I get an exception that says that the Binary operator for \"System.Collections.Generic.ICollection`1[System.Int32]\" and \"System.Int32 is not defined With Linq 1.0 it w...

NHibernate: Generate mappings for stored procedures

I need to call some stored procedures via NHibernate (not necessarily for CRUD-operations). Is there a freeware/open source tool which can generate mappings (a hbm.xml) for stored procedures and tables? ...

Implementing IPropertyAccessor NHibernate

Hi All, During usage of NHibernate ... One strange problem that I have bumped into was multiple updates after Session.Flush() command. No data actually changed ... Just wanted to perform Select that all, in my case there was 1000 updates – one per returned row!!! Such behavior happens only if I’m using properties with custom Propert...

NHibernate Criteria select items by the group by and sum of itemid within another table.

public class SearchText { public virtual int Id { get; set; } public virtual string Text { get; set; } } public class SearchTextLog { public virtual int Id { get; set; } public virtual SearchText SearchText { get; set; } public virtual User User { get; set; } public virtual int SearchCount { get; set; } publi...

How can I filter an object nested in a object by the type?

ICriteria iCriteria = DataAccessHelper.GetSession().CreateCriteria(typeof(T)) .Add(Expression.Lt("Id", InitialIndex)) .Add(Expression.Eq("Member", member)) .Add(Expression.Eq("Action.class", typeof(U))) .SetMaxResults(MaxResult) .AddOrder(Order.Desc("Id")); I basically...

How to obtain NHibernate generated SQL in code at runtime?

I know you can view the NHibernate generated SQL by hooking it up to log4net or piping it out to the console ("show_sql" option), but is there any way to obtain the generated SQL in code at runtime? What I would like to be able to do is take an ICriteria object (or IQuery) and dump the generated SQL to the screen or custom log (not log4...

Force all nhibernate proxies to be load for an instance...

I want to take a snapshot of an instance of an entity and therefore I want to force all proxies to load for this instance. I don't want disable lazy loading for the majority of the time I just wondering if there is an API I can call to force all proxies to be loaded. ...

NHibernate One-To-Many Using A Join Table

Is this possible without mapping the join table to a domain entity? For example if I have the following three tables, account and note are joined by the table account_note. Can i map a collection of notes to account class with a one to many mapping? 1 to M | 1 to M Account -> Account_Note -> Note ...

Nhibernate multiple unique-key on same field

I have a hierarchical structure like this: class Node { Node Parent; string Name; string Code; } and I need to reflect in nhibernate mapping files that the combinations (Parent, Name) and (Parent, Code) BOTH are unique (even when Parent is null). Does nhibernate allows multiple unique-key on the same field? Something in the like...

Mapping a Private Field in NHibernate (with Fluent NH)

Hi friends! I'd like to know, How Could I map (with fluent nhibernate) this model: public class Category { private IList<Product> _products; public IEnumerable<Product> Products { get { return _products; } } /* others properties */ public Category() { _products = new List<Product>(); } // to add...

how to delete/change items in a one-to-many relation

HI all, I'm new to hibernate and I don't know how to handle correctly the updating of items on a one-to-many relation. My scenarion whould be: class image { ILIst Relations; } class Mapping { Image Parent; OwnerId; OwnerType; } When I want to change the images attached to a owner I do: for each 'mappings for Owner X' { del...

NHibernate FlushMode Auto Not Flushing Before Find

All right, I've seen some posts asking almost the same thing but the points were a little bit different. This is a classic case: I'm saving/updating an entity and, within the SAME SESSION, I'm trying to get them from the database (using criteria/find/enumerable/etc) with FlushMode = Auto. The matter is: NHibernate isn't flushing the upd...

How do I get NHibernate to do a join?

I've used Fluent NHibernate to hook up a store and employee class where Stores can have many employees as follows: public class Store { public virtual IList<Employee> Employees { get; set; } //other store properties } public class Employee { public virtual Store Store { get; set; } public virtual bool? SomeStatus1 { ...