nhibernate

Partial lazy loading

I've one object User which can have multiple Posts. Example: Load the user with lazy loading on the Posts IList<User> users = User.LoadAll() Then I want to read only "half" of the users[2].Posts[3] (retrieve only the attributes that I want and not all of them from that post object), is this possible to make? (Note, I do not want to u...

NHibernate and Large Collections

As a way to learn NHibernate, I came up with a small project that includes a typical users & groups authentication system. It got me thinking about how this would be done. I quickly put together the following classes and mapped them to the database, which worked after a lot of trial and error. I ended up with a three-table database sc...

How to efficiently delete all but the latest x children of parent entity using NHibernate?

Hi, Please forgive me if I don't explain this very well. First off, I am using NHibernate 2.0 with .NET 3.5. Basically I have an entity "EntityA" (for simplicity) with one or more children of type EntityB. Each EntityB has a number indicating how recently it was created. I would like to delete all but the x most recent EntityB. This for...

BDD/DDD Where to put specifications for basic entity validation?

Alternatively, is basic entity validation considered a specification(s)? In general, is it better to keep basic entity validation (name cannot be null or empty, date must be greater than xxx) in the actual entity, or outside of it in a specification? If in a specification, what would that look like? Would you have a spec for each fiel...

Linq to Nhiberate - Where clause

I have tried to find an answer to this, but could not find one in google. Probably not searching the correct terms, so thought I would ask here. The following returns all my contacts, not the ones that equal the adjusterType sent in. var contacts = from c in session.Linq<Contact>() select c; contacts.Where(c => c.ContactAdjuster.Adjus...

How can I do generic field and component-level change tracking in NHibernate?

In my application, I've got a few different types of entities that I have a requirement to do field-level change tracking on. I've googled for this and only can come up with examples on doing simple "Date Inserted" and "Date Updated" audit tracking where you just modify fields on the entity being persisted already. My requirements are mo...

nHibernate & sqlite mappings

I'm having real problems with setting up nHibernate with sqlite. Here is the hibernate.cfg.xml file: <?xml version="1.0" encoding="utf-8" ?> <hibernate-configuration xmlns="urn:nhibernate-configuration-2.2"> <session-factory> <property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property> <prope...

Fluent NHibernate HasMany Collection Problems

Update: It appears that changing my mapping from Cascade.All() to Cascade.AllDeleteOrphan() fixes most of my issues. I still have to explicitly set the Company property on the OperatingState, which seems unnecessary as it's being added to the Company entity, but at least I can work with that during an update. I still need to test that wi...

Nhibernate, fill one-to-many associations

For example, i have two classes with parent - child relation: ParentClass, ChildClass. ParentClass has ISet<ChildClass> Children property. Is it possible with single HQL to initialize all parent objects with its childrens. ...

Save entities received from WCF service

In my application I need to save with NHibernate entities received from WCF service. Currently I'm using session SaveOrUpdate method for this purpose. Often we don't need to edit reference properties, so from client I receive object, which has empty collections. But I don't want this empty collection to reflect in database. Example: ...

Is Linq to SQL still a viable choice for developing applications?

I'm reading up on .NET things again after a brief (and occasionally ongoing) stint with Ruby on Rails. I'm wondering if LINQ is still a choice when choosing an ORM for new applications, or if I should learn something like NHibernate instead which seems to still be going strong. I know that Linq has basically been subsumed by the Entity...

Hibernate complex Mappings

We use a pesonal design to store modified rows. For the data we need to keep, we use 2 tables; the first with fields that don't change, the second uses soft delete. +----------+ +---------------+ | TableBase| | Table | +==========+ +===============+ | Id | | TableId | | FieldA | | Id | +--------...

NHibernate - child object is null

Using NHibernate 2.0, NHibernate class attributes for mappings, ASP.NET MVC to create a message board type app. I have 2 entities, Post and User. Post has an Owner property which is an instance of User. It also has a Replies property which is a collection of type ISet. The idea is that one post can have one level of replies, the same...

Is it possible to use NHibernate without altering a DDD model that is part of a framework

I dig a lot of things about the DDD approach (Ubiquitous language, Aggregates, Repositories, etc.) and I think that, contrary to what I read a lot, entities should have behavior rather then being agnostic. All examples I see tend to present entities with virtual automatic properties and an empty constructor (protected or worst, public) a...

Fluent NHibernate Automap does not take into account IList<T> collections as indexed

I am using automap to map a domain model (simplified version): public class AppUser : Entity { [Required] public virtual string NickName { get; set; } [Required] [DataType(DataType.Password)] public virtual string PassKey { get; set; } [Required] [DataType(DataType.EmailAddress)] public virtual string E...

Person -> Details with lazy loading

Yesterday I`ve asked a question Person -> Details database structure Now I need to make a NHibernate mapping, where the details are lazy loaded. so my person map is: <class name="Employee" table="Employee"> <id name="Id" column="EmployeeId"> <generator class="native" /> </id> <property name="FName" column="FName"/> ...

How to map Type with Nhibernate (and Fluent NHibernate)

Let's say I have something similar to this : public class DataType { //For NHibernate private DataType(){} public DataType(string name, Type type, string defaultValue) { Name = name; TypeOfContent = type; DefaultInvariantStringValue = defaultValue; } public string Name { get; set; } ...

NHibernate, transactions and TransactionScope

I'm trying to find the best solution to handle transaction in a web application that uses NHibernate. We use a IHttpModule and at HttpApplication.BeginRequest we open a new session and we bind it to the HttpContext with ManagedWebSessionContext.Bind(context, session); We close and unbind the session on HttpApplication.EndRequest. In ou...

Select n+1 problem

Foo has Title. Bar references Foo. I have a collection with Bars. I need a collection with Foo.Title. If i have 10 bars in collection, i'll call db 10 times. bars.Select(x=>x.Foo.Title) At the moment this (using NHibernate Linq and i don't want to drop it) retrieves Bar collection. var q = from b in Session.Linq<Bar>() ...

How to Map oracle datatype SYS.XMLTYPE in Nhiberbate

Hi, I have a table in oracle having column of datatType SYS.XMLTYPE and have to map it in Nhibernate hbm to retrieve the XML. I am using C# with .net framework 3.5 is there any specific dataType available to map this or can i use byte[] or char[] for mapping? Thanks Arvind ...