开发者

FluentNHibernate: HasMany mapping to methods (their backing fields)? / Foreign key not saved

开发者 https://www.devze.com 2023-03-07 09:09 出处:网络
Is it possible to map to methods instead of properties? I have a Customer class with a method \"GetOrders()\" typeof \"ReadOnlyCollection\" with backing field \"_orders\" typeof \"IList\".

Is it possible to map to methods instead of properties?

I have a Customer class with a method "GetOrders()" typeof "ReadOnlyCollection" with backing field "_orders" typeof "IList".

I tried in CustomerMap:

HasMany<Order>(Reveal.Member<Customer>("_orders"))
    .KeyColumn("CustomerId").Cascade.All().Inverse().Not.LazyLoad();

But I get an exception when running the insert for a customer containing 1 order.

 Cannot insert the value NULL into column 'CustomerId', table 'Order'; 
 column do开发者_开发知识库es not allow nulls. INSERT fails.

Does mapping methods (or at least their backing fields) not work? Or am I doing something else wrong?


The problem was that I did not map the Customer to the Orders also.

0

精彩评论

暂无评论...
验证码 换一张
取 消