fluent-nhibernate

Fluent mappings between existing and new tables

Problem is simple I have two classes mapped with fluent nhibernate : public class A: EntityBase {} public class B: EntityBase { public virtual A A_Something {get;set;} } with EntityBase class providing only Key property. Now i want to map them and configure my db. So here are mappings public class AMap : DomainEntityBase<A> { pu...

Fluent Nhibernate ClassMaps and Column Order

Our entities have a group of common properties. In order to reduce repetitive mapping, I created a base ClassMap that maps the identities and common properties. For each entity's ClassMap I just subclass the base and it works great. For a new project we are also letting NH generate the DB schema for us. The issue is, the order of the col...

NHibernate Mapping Property Beyond LINQ Querying

Hi, my application has the following entity: public class User { public virtual int UserID { get; set; } public virtual Membership LatestMembership { get { return Membership.First(); } } public virtual IList<Membership> Membership { get; set; } public User() { Membership = new List<Membership>(); } } W...

NHibernate Validator and Schema Export question

I'm learning to use NHibernate validator and it's Fluent API (Loquacious). I have noticed is that I can't set an integer property or nullable int property (int?) to be not nullable. Well, why not? In a database, an integer column can have null values. Even worse, when I generate DDL using SchemaExport, the integer column wont be pickin...

NHibernate Many-to-one cascading delete (how to?)

Hi, I have this scenario: public class Survey : EntityBase { public virtual string Name { get; set; } } public class Response : EntityBase { public virtual string Name { get; set; } public virtual Survey Survey { get; set; } } public class SurveyMap : ClassMap<Survey> { public SurveyMap() { this.Id(e => e.I...

2010 Beginners guide to fluent nHibernate

I need some tutorials on how to get started with nHibernate and Fluent nHibernate. I'm coming from an Entity Framework background (which seems easier to use). I've tried sites like http://www.summerofnhibernate.com/ to get a grasp on nHibernate itself, but it seems outdated. I'd like to generate a mapping of my database tables (al la En...

"References" property not visible on the client's side

So as usual I have an issue with ria service + nhibernate. The question is how to make an entity property , mapped using “references”, visible on the client side. The problem is that when you load an entity without this field and try to save it , then missing values are updated as NULL inside db. Here’s class schema: public class A {...

Fluent NHibernate - Problems adding a discriminator

I have a class, Document and several sub-classes (Invoice, PurchaseOrder, etc). I've added a discriminator to Document like so: public class DocumentMapOverride : IAutoMappingOverride<Document> { public void Override(AutoMapping<Document> mapping) { mapping.DiscriminateSubClassesOnColumn("DocumentType"); } } My un...

Saving multiple child entities in NHibernate, at once.

I'm getting the "Save unsaved transient entities" error in NHibernate. I have an aggregate root, neighborhood that contains addresses and person, here's some quick pseudo code to explain the relationship: public class Neighborhood { public virtual int Id { get; set; } public virtual IList<Address> Addresses { get; set; } } public...

nhibernate +fluent +mapping

Hi all. I have a table http://img36.imageshack.us/i/beztytuuszxq.png/ and mapping: public class CategoryMap : ClassMap<Category> { public CategoryMap() { Table(FieldNames.Category.Table); Id(x => x.ID); Map(x => x.Name).Not.Nullable(); Map(x => x.ShowInMenuBar).Not.Nullable(); References(x...

Cascade insert on one-to-many with fluent NHibernate

Hi, I have two classes mapped using fluent NHibernate - User and a UserRoleAssignment. An User has many UserRoleAssignments. Here's the relevant map for user: HasMany(x => x.Roles) .Table("UserRoleMap") .Cascade.SaveUpdate(); And for UserRoleAssignment: Map(x => x.User_Id); As you can see, I'm only referencing from User to UserRol...

Fluent NHibernate hasmany save inser null value

hi guys, i'm new to nhibernate so maybe the response depends on my lack of knowledge. I created these two tables: (sorry for italian language, i hope you can understand withouth any problems). Then, i have these object in my model: [Serializable] public class Profilo { public virtual int Id { get; set; } public virtual stri...

Howto ensure objects are lazy loaded with (Fluent) NHibernate?

I have an application using Fluent NHibernate on the server side to configure the database. Fluent uses Lazyloading as default, but I explicitly disabled this as this gave me problems when sending the objects to the client side. Obviously the client can't load the objects lazily as it doesn't have access to the database. Now I try reen...

FluentNHibernate Where clause does not appear to be used when populating collections

I use a Where clause in my FluentNHibernate mappings as follows: public class FooMap : ClassMap<Foo> { public FooMap() { Table("MySchema.Foos"); Where("Deleted = 0"); etc etc } } This where clause gets appended to the SQL when I load individual Foo instances through session.Load<Foo>(1) and when I use LINQ queries. H...

NHibernate.Linq count throws NHibernate.QueryException : could not resolve property

I'm building an ecommerce site using S#arp Architecture. I'm trying to map a hierachy of categories and retrieve the top level categories. I'm using NHibernate.Linq for this. I have the following entity: public class Category : Entity { #region Properties [DomainSignature] [NotNullNotEmpty] public virtual string Name {...

NHibernate Projections Duplicates To List

I have a problem with nHibernate projections. I don't even know if what I'm attempting can be done but if any nHibernate experts can help me I'd be grateful. I'm using nHibernate criteria to query a database and I'm returning the result projected to a different (slimmed down) object. I get a list of returns like Id CompanyId Descr...

How to model this classes withN Hibernate and Fluent.NHibernate Maps?

Hi. I'm using ASP.NET MVC with NHibernate and Fluent.NHibernate Maps. I would like to know how to map the classes on Fluent and to create the database tables on my MySQL: public class AgenteDeViagem { public virtual int Id { get; set; } public virtual string Email { get; set; } public virtual AgentePessoa AgentePessoa { ge...

Updating schema of production database with NHibernate and adding default data

I'm looking for some ideas on how other people are managing the following situation - I've got some ideas but they seem a little messy and I can't help thinking I'm missing something. Here's the situation: You're using NHibernate with Fluent NHibernate for mappings. You have an application in production with a database with live data ...

Fluent NHibernate PersistenceSpecification can't test a collection of strings

I'm using Fluent NHibernate to map a a class that has a collection of strings like this: public class Foo { public virtual ICollection<string> Strings { get; set; } } public class FooMap : ClassMap<Foo> { public FooMap() { HasMany(f => f.Strings).Element("SomeColumnName"); } } When I write a unit test using the PersistenceSpe...

Unable to create strongly typed view in VS2010 with Fluent Nhibinate and MVC2

HI, I was wondering if any one else had had a problem with VS2010 MVC 2 projects not being able to automaticly create a strongly typed view after doing a fluent mapping? When trying to do the mapping VS2010 doesnt show the Entities in the drop down and even if i manually put the class in it doent auto build the view . Cheers Dan ...