nhibernate-mapping

NHibernate mapping with forking inheritance model

I'm just starting out with NHibernate and am trying to do a mapping for my model. (this is a model-first, TDD approach, just creating the database now) My Class hierachy is something like : I'm trying to work out how to map this now using a mapping xml file? This is my table and what I want them to map to QuestionId - Int - [Quest...

NHibernate Auditing - PostInsert Not Working

Hi, my application has the following entities: public class User { public virtual int UserID { get; set; } public virtual string UserName { get; set; } public virtual IList<UserLog> Log { get; private set; } public User() { Log = new List<UserLog>(); } } public class UserLog { public virtual int Use...

How to make NHibernate serialize a given property to a binary field?

Hi everyone, I have a simple ASP.NET MVC web application that uses NHibernate with FluentNHibernate's auto mapping feature for its data access. I have encountered a scenario in which I would like NHibernate to persist some classes as binary data. For example, I have something similar to this: public class User { ... // This f...

NHibernate many-to-many self referencing joins

I have a site where a person can follow someone and also be followed. I am not sure how to map this for my specific scenario. My database schema is currently like this A Person table with a PersonID, Name etc. A PersonFollow table with PersonFollowID (Identity), PersonID, FollowID, Timestamp. The PersonID represents a user while the Fo...

NHibernate Mapping : How to map rows based on a field value

I have a [ContactNumbers] table as defined below: ID (PK) | PersonID (FK) | NumberType | Number ========|===============|============|======= and a classes defined as: public class Person { ContactNumber homePhone; ContactNumber workPhone; } public class ContactNumber { string Number; } How would I define my HBM mappin...

How do I define a NHibernate sql-query using mapping attributes in C#?

So for a project that we are working on we have our entire domain model mapped using mapping-attributes on the business entities themselves. I have a working sql-query mapping that I would like to define using the mapping-attributes but I am not sure how to do this. Any help is appreciated. Here is the xml mapping that needs to be trans...

Get field by field mapping in dozer

Hello! I am using dozer to map bean properties. The way I do it is : dozerMapper.map(sourceClass, destClass). This returns entire mapped class. However, Is there a way to get what individual property is mapped to? E.g if SourceClass has propA, is there a simple way to get the corresponding property in DestClass to which propA is mapped ...

Mapping abstract base classes using Fluent NHibernate Automapper

I'm using Fluent NHibernate's automapper to map the following domain model (via AutoMap.AssemblyOf<Ticket>()), but it's throwing an exception when creating a SessionFactory. class Ticket { Owner TicketOwner { get; set; } Owner CreatedBy { get; set; } } abstract class Owner { ICollection<Ticket> OwnedTickets { get; set; } ...

NHibernate creating a proxy instance failed due to abstract method

I'm new to NHibernate, and am trying to map a domain model that has a bit of inheritence etc (see this question for full details on my model, starting a new question as this is a different error) My base class has some abstract methods that each class beneath has to implement. This appears to be causing problems with NHibernate, even th...

unique in .hbm.xml file not raising exception

I am having the following in my .hbm.xml file <?xml version="1.0" encoding="utf-8" ?> <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" namespace="Core.Domain.Model" assembly="Core"> <class name="Category" table="Categories" dynamic-update="true"> <cache ...

Tricky Fluent Nhibernate modeling with subs of subclasses

I'm moving a project off of a custom DAL and onto Nhibernate but I've run into a tricky mapping scenario that I don't know how to resolve. Essentially, there are sub classes of a subclass without a discriminator value. The primary subclass has a discriminator value so that was trivial. The issue arises when I get to the third level. The...

Fluent Nhibernate, how to handle a has many that really only has one?

Currently I have a table "ComponentAnalysis" and a table "HistoryOfUse" that I am trying to map in Fluent NHibernate. A component analysis should only have 1 history of use and a history of use should belong to 1 component analysis. This would suggest to me that the tables should be set up for a 1 to 1 mapping. But the designer of the D...

Mapping one colun twice in fluent nhibernate

Here we go... I have a table (which unfortunatelly I can't change) with columns like: date, startTime, endTime. And I have data classes with two fields: startDateTime = date + startTime endDateTime = date + endTime Map(x => x.EndDateTime) .Columns.Clear() .Columns.Add("date", "endTime") .Custo...

NHibernate - KeyColumn from Parent Table

Hi, my application has the following database structure: Transactions: - TransactionID (PK, Identity) - Type - TotalAmount TransactionDetails: - TransactionDetailID (PK, Identity) - TransactionID (PK) - Amount ProductTransactions: - TransactionID (PK, FK) - Discount ProductTransactionDetails: - TransactionDetailID (PK, FK) - ProductI...

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...

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.StaleStateException : Unexpected row count: 0; expected: 1

Hl Guys, I am busy writing a backend administrative program for a system that exists. I have selected NHibernate for my data access solution and am fairly new to it. I am experiencing the following error in a parent/child relationship: NHibernate.StaleStateException : Unexpected row count: 0; expected: 1 This error is caused by the fa...

Can you change from a base class to a joined subclass type in nhibernate?

I have document scanning system where several types of documents are scanned. Initially, the document has no information when its scanned, then they get classified and additional information is entered for them in a second step later. So, I have a base class called Document, and subclasses for each type with their respective metadata lik...

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...

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...