nhibernate-mapping

nHibernate filter does not work when lazy loading is disabled?

I am using nHibernate 2.1.2.4000 with Asp.Net 4. I also have a mapping defined for an Entity. The mapping also defines a filter named CultureCode. <?xml version="1.0" encoding="utf-8" ?> <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"> <class name="Demo.EntityCore.Domain.Option, Demo.EntityCore" table="tbl_options"> <...

NHibernate Mapping - many-to-one via table

I'm working with an existing database that has the following structure. Changing the database schema is a last resort. Products Id Name ParentProducts ParentId ChildId I don't want an entity for ParentProducts, I have the following for the children property (still need to test it, but that's the concept). <bag name="Chil...

Using NHibernate Restrictions without strings in the property name.

When you create a criteria, you can add Restrictions that apply to a property. There are 2 ways of creating a Restriction: Restrictions.Eq(string propertyName, object value) or Restrictions.Eq(IProjection projection, object value) Thing is, I don't feel comfortable passing property names as strings, since if they ever change, my projec...

How to Map a VIEW without unique identifing column with Fluent Nhibernate

hi, i have readonly VIEWs in an existing Database and i'd like to get them with FHN. i tried mapping it the following way: public class HhstMap : ClassMap<Hhst> { public HhstMap() { Table("HHST"); ReadOnly(); Id(); Map(x => x.Hkz); Map(x => x.Kapitel); Map(x => x.Titel); ...

How to set discriminate column type for subclass with FNH?

What is the new SetAttribute() in FNH mapping? I need to set my discriminator value on subclass because String is not preferred - old post with NH 2.1.2.4000, FNH 1.1.0.689 public class BaseBuildingMap : ClassMap<BaseBuilding> { public BaseBuildingMap() { Id(x => x.Id); DiscriminateSubClassesOnColumn<int>("Build...

Fluent NHibernate - mapping an Entity as a different type

I have a class which I would like to map as a component onto any table which contains it: public class Time { public int Hours { get; set; } public int Minutes { get; set; } public int Seconds { get; set; } } I would like to store this class as a bigint in the database - the same as how TimeSpan is stored but my class has ...

NHibernate: link a collection via something other than the PK

Suppose I have the following tables: Company Person Address ---------------------------------------------------------------------------- Id (PK) Id (PK) Id (PK) Name CompanyId (FK) CompanyId (FK) AccessType AddressType Corresponding t...

NHibernate Log Tables to Track all Changes to a Table

Hi, i have the following db structure: Users: - UserID - UserName - FirstName - LastName ... UsersLog: - UserLogID - UserID - UserName - FirstName - LastName ... - DateCreated The log table simply inserts a record against the user everytime an insert or edit is made. The reason i have the log table is that when an order is submitted...

Using a reference as id in fluentnhibernate

I have a child table containing an id to the parent. This is a one to one mapping, but the child table might be missing values. I'm having problems mapping this without getting an error though... I've tried several things; mapping the same column, having distinct properties etc.. Parent table int id Child table int parentid Paren...

Securing/omitting selected properties of a domain entity in NHibernate (subclass, projection, ?)

Consider the following simplified scenario: public class Person { public string Name { get; set; } public int Age { get; set; } // restricted public string SocialSecurityNumber { get; set; } // restricted public string MothersMaidenName { get; set; } } So, in the application, many users can view Person data....

Add/delete item to bag collection

I am working with nHibernate, and trying make sense of bag collections. My data structure is relatively straight-forward... Entry: <class name="Entry"> <id name="id" column="EntryId"> <generator type="guid.comb"/> </id> <property name="Name" column="Name"/> <bag name="Results" table="Results" cascade="all"> <key column="Ent...

Mapping person and employee in Fluent NHibernate

How can I map following queries using Fluent NHibernate (entity, mapping class etc..), the employee ids are stored in identifier tables. Person table contains employee information and non-employee information. SELECT p.Id, p.FirstName, p.LastName FROM Person p UNION ALL SELECT e.Id, e.FirstName, e.LastName FROM Employee e ...

NHibernate One-To-One Relationships not saving correctly

I am having an issue with saving entities with one-to-one relationships. I just want to save the parent entity and have the child be save aswell but I am having to save both separately. This is an example of what I am having to do, otherwise the child is not saved. var session = SessionProvider.OpenSession.Session; using (...

Filters not being applied for many-to-one reference

I have a bit of an odd scenario where I have a table that references a view that contains rows which are user-specific. The view has a unique row ID, but it is never used to reference the item. Instead a unique value is derived from a combination of a client ID, user ID, and an object key. public BarMap() { Table(Datab...

NHibernate -- How to fake one side of a many-to-many normalization

Hi, I have the following two tables: Package id ClientPackage id clientNumber packageId The thing is that I do not have a Client table in this database (it resides in another database). Is there a way that I can create a Client mapping to a Client model which just consist of distinct "clientNumber" from the ClientPackage table whil...

How to handle a large ammount of mapping files in nHibernate

Hello, we're working on a large windows forms .net application with a very large database. currently we're reaching 400 tables and business objects but thats maybe 1/4 of the whole application. My question now is, how to handle this large ammount of mapping files with nhibernate with performance and memory usage in mind. The business ...

Implementing Nhibernate one to many mapping

Hi, I have a class School and another class Teachers. now every school can contain m Teachers and one Teacher may be part of more than one school. But in the Teachers class I dont want a property that tells me which Schools a teacher is part of. Thus, public class School { public virtual int Id {get;set;} public virtual string Name {g...

NHibernate 3 Alpha - proxyfactory.factory_class?

Hi, Im playing around with NHibernate 3 alpha but struggling to set up my SessionFactory. I have the following: var config = new Configuration().Configure(); _sessionFactory = config.BuildSessionFactory(); However, in the provided dlls with the 3 alpha download there are no provided proxy factory classes. Ie NHibernate.ByteCode.Ca...

Multiple ClassMaps classes in NHibernate

Is this possible in fluent nhibernate having multiple mappings for one table? Lets suppose i have a Users table. Once i want it to be apped exactly like in file UserMap1.cs, and some times I would rather prefer mapping from UserMap2.cs. I don't need to switch configurations while app is running. I just have to choose a proper one at th...

How can I map NHibernate domain classes with an existing table

Hi I am presently trying to use NHibernate on a project where I do not have permissions to CREATE TABLE in SQL 2005. I keep getting a mapping error, and my assumption is that I do not setup the table by generating it. Is it fair of me to assume that NHibernate can only map successfully with tables that were generated by its tool? If n...