fluent-nhibernate

Mapping a read-only property with no setter using Fluent NHibernate

心已入冬 提交于 2019-12-22 07:53:42
问题 I have a domain class that looks like this. I want NHibernate to save the current value of LastUpdate when inserting/updating so that I can use it in queries, but to ignore it when retrieving a Foo from the database and let the object itself recalculate the value when I actually access it. public class Foo { public DateTime LastUpdate { get { /* Complex logic to determine last update by inspecting History */ return value; } } public IEnumerable<History> History { get; set; } /* etc. */ } My

Mapping a read-only property with no setter using Fluent NHibernate

假装没事ソ 提交于 2019-12-22 07:53:07
问题 I have a domain class that looks like this. I want NHibernate to save the current value of LastUpdate when inserting/updating so that I can use it in queries, but to ignore it when retrieving a Foo from the database and let the object itself recalculate the value when I actually access it. public class Foo { public DateTime LastUpdate { get { /* Complex logic to determine last update by inspecting History */ return value; } } public IEnumerable<History> History { get; set; } /* etc. */ } My

How to set the timeout on a NHibernate transaction

孤街醉人 提交于 2019-12-22 06:48:32
问题 I need a lot of DB processing done in a single transaction, including some processing using NHibernate. To make everything work in the same transaction, I'm using NHibernate's Session to start it, and enlist the the commands for the other work in it. Everything goes OK until I commit. At that time I get a transaction timeout. How can I set the NHibernate transaction timeout value sufficiently high? We use FluentNHibernate. 回答1: After some trial and lots of error I found this: It appears that

NHibernate fluent HasMany mapping inserts NULL Foreign key

℡╲_俬逩灬. 提交于 2019-12-22 06:34:15
问题 I have an entity Company that has many Orders. I mapped these as following to each other: Company HasMany(x => x.Orders).KeyColumn("CompanyID").Cascade.All().Inverse(); Order References(x => x.Company).Column("CompanyID") However when i create a new order for the company and try to save it, I get a SQL error: "Cannot insert the value NULL into column 'CompanyID', table 'Orders'; column does not allow nulls. INSERT fails." (this is the generated SQL statement: INSERT INTO Order (Name,

Fluent NHibernate - HasMany on composite key

邮差的信 提交于 2019-12-22 06:27:22
问题 How do you create a HasMany relation on a legacy database which has no Foreign Key and columns differently named? I know how to create a one-to-one relation on HeaderVersion using References, but don't know how to create HasMany from Header 1 to * HeaderVersion. Join condition should be: Header.Id1 = HeaderVersion.PId1 AND Header.Id2 = HeaderVersion.PId2 Domain: public class Header { public virtual int Id1 { get; set; } public virtual int Id2 { get; set; } public virtual string Something {

Fluent NHibernate join not using primary key

我的未来我决定 提交于 2019-12-22 04:39:17
问题 I am trying to get a single property from a joined table where a non-PK in my main table is joined to the PK of the foreign table. Below is an oversimplified example of what I am trying to accomplish ( I do not want to reference the foreign entity ): Tables: CREATE TABLE Status ( Id int, Body text, CategoryId int ) CREATE TABLE Category ( Id int, Name text ) SQL to generate: SELECT Id, Body, CategoryId, Category.Name AS CategoryName FROM Status LEFT JOIN Category ON Category.Id = Status

How can I Change the default scale and precision of decimals in Fluent NHibernate?

亡梦爱人 提交于 2019-12-22 04:34:29
问题 In the application I'm building, I have many decimal fields with a specific precision and scale that need to be mapped from a database. I can achieve this by using the Precision() and Scale() methods: public class ClassAMap : ClassMap<ClassA> { public ClassAMap () { Map(x => x.Value).Precision(22).Scale(12); } } Is there any way to change the default precision and scale for decimals, so I don't need to remember to add the calls to Precision() and Scale() for every decimal mapped? 回答1: You can

Fluent NHibernate — Saving Entity with Composite Key

我们两清 提交于 2019-12-22 04:07:23
问题 First, I have the following table: CREATE TABLE CustomerHub ( CustomerId INT NOT NULL, HubId INT NOT NULL ) Which I have mapped to the this entity: public class CustomerHub { public int CustomerId {get;set;} public int HubId {get;set} //GetHashCode, Equals, Etc... } Using this mapping: public class CustomerHubMap : ClassMap<CustomerHub> { UseCompositeId() .WithKeyProperty(x => x.CustomerId) .WithKeyProperty(x => x.HubId); } The problem I have is that when I create a new entity of type

Fluent NHibernate — Saving Entity with Composite Key

老子叫甜甜 提交于 2019-12-22 04:07:12
问题 First, I have the following table: CREATE TABLE CustomerHub ( CustomerId INT NOT NULL, HubId INT NOT NULL ) Which I have mapped to the this entity: public class CustomerHub { public int CustomerId {get;set;} public int HubId {get;set} //GetHashCode, Equals, Etc... } Using this mapping: public class CustomerHubMap : ClassMap<CustomerHub> { UseCompositeId() .WithKeyProperty(x => x.CustomerId) .WithKeyProperty(x => x.HubId); } The problem I have is that when I create a new entity of type