English 中文(简体)
nhibernate hasmany when not using foreign key
原标题:

Let say I have a request table, that looks as follows:

RequestId INT  
ReferenceNumber VARCHAR

Each request is logged in a requestlog table. There are no foreign keys between the tables:

RequestLogId INT  
ReferenceNumber VARCHAR  
Content VARCHAR  

The requestlog contains the content of the request, and this content needs to be stored for a period of time. The request can be deleted, but the log can only be deleted after a period of time.

How can I map my request object so that it can contain a list of requestlogs, based on the referencenumber?

I tried this:

Table("InsuranceRequest");  
Id(i => i.Id).Column("InsuranceRequestId");  
Map(i => i.ReferenceNumber);  
HasMany(i => i.InsuranceRequestLog).KeyColumn("RefenceNumber").LazyLoad.Cascade.None();

It doesn t work though. This mapping tries to map the referencenumber to the RequestLogId of requestlog. Is there a way to specify that the joining column should be the insurancerequestlog referencenumber?

最佳回答

nothing prevent the many to many in your table structure.. i recommend to change the structure and make them foreign keys, and i m sure that the many to many mapping will work for u if the mapping i not working after the structure change.

another tip for u: take an empty db and try expose schema.. than u ll be able to see what nhibernate think the structure should look like

问题回答

暂无回答




相关问题
nHibernate one-to-many inserts but doesnt update

Instead of getting into code, I have a simple question. Default behavior for a simple one-to-many is that it inserts the child record then updates the foreign key column with the parent key. Has ...

How Do I copy an existing nhibernate object as a new object?

I a persisted NHibernate object that I would like to repersist as a new entity. How do I get NHibernate to save this object as if it was a new? I am thinking I might create a session interceptor to ...

join across databases with nhibernate

I am trying to join two tables that reside in two different databases. Every time, I try to join I get the following error: An association from the table xxx refers to an unmapped class. If the ...

WPF - MVVM - NHibernate Validation

Im facing a bit of an issue when trying to validate a decimal property on domain object which is bound to a textbox on the view through the viewmodel. I am using NHibernate to decorate my property on ...

NHibernate Search in a List using ICriteria

I have my class X : public class ClassX { public virtual IList<ClassY> ListY { get; set; } ... } My ClassX mapping (using Fluent) ... HasMany<ClassX>(x => x.ListY ) ....

热门标签