fluent-nhibernate-mapping

Fluent NHibernate DateTime UTC

一笑奈何 提交于 2021-02-07 09:45:48
问题 I would like to create a fluent nhibernate mapping to map a DateTime field in a following way: On save - Save the UTC value On read - Adjust to local time zone value What is the best way to achieve this mapping? 回答1: Personally, I would store the date in the object in UTC, then convert within the object when reading/writing. You can then reference the backing field your property uses in the mapping (it's not quite as "fluent" to do it this way but you can use FluentNH to map this). If the UTC

Mapping private attributes of domain entities with Dapper dot net

那年仲夏 提交于 2021-02-06 11:53:01
问题 In most of my projects I use nHibernate + Fluent mapping and recently I've started to play around with Dapper to see if I can move read operations to it. I follow DDD approach so my domain entities do not have any public setters. For example: public class User { private int _id; private string _name; private IList<Car> _carList; protected User(){} // Fluent Mapping public User(string id, string name) { // validation // ... _id = id; _name = name; } public int Id{ get {return _id;} } public

Mapping private attributes of domain entities with Dapper dot net

半腔热情 提交于 2021-02-06 11:52:54
问题 In most of my projects I use nHibernate + Fluent mapping and recently I've started to play around with Dapper to see if I can move read operations to it. I follow DDD approach so my domain entities do not have any public setters. For example: public class User { private int _id; private string _name; private IList<Car> _carList; protected User(){} // Fluent Mapping public User(string id, string name) { // validation // ... _id = id; _name = name; } public int Id{ get {return _id;} } public

Mapping to a different view based on child type

做~自己de王妃 提交于 2020-01-17 04:27:10
问题 So i have a situation where i have common base type but i need to map to a different view based on the child type. It looks like i can use a generic mapping class to handle the inheritance http://geekswithblogs.net/nharrison/archive/2010/07/09/inheriting-a-class-map-in-fluent-nhibernate.aspx But how can i conditionally map to a different view based on the child type? I see an EntityType property but it says its obsolete and will be made private in the next version. As an example i have a base

Map a collection of custom types on fluent nhibernate

╄→尐↘猪︶ㄣ 提交于 2020-01-15 11:14:13
问题 I have a Custom Type on Fluent NHibernate and I need to map it to a collection of its type, using HasMany association. However, Fluent Nhibernate doesn't let me indicate on HasMany that its about a custom type like I do in my regular types. This is my code: HasMany(x => x.AvailablePaymentOptions) .KeyColumn("OFFER_ID") .Cascade.None() .KeyNullable() .Not.LazyLoad(); Any thoughts? Thanks 回答1: Finish not using the custom type, but instead, mapping a component: HasMany(x => x

FluentNhibernate + private set

时间秒杀一切 提交于 2020-01-14 14:33:11
问题 I'm using auto property with private set, and fluentNhibernate throw an error for me... FluentNHibernate.Cfg.FluentConfigurationException: An invalid or incomplete configuration was used while creating a SessionFactory. Check PotentialReasons collection, and InnerException for more detail. * Database was not configured through Database method. This is my class: public class MyClass { public virtual int Id { get; set; } public virtual string PropOne { get; private set; } } This is my map:

FluentNHibernate or port to NHibernate mapping by code

这一生的挚爱 提交于 2020-01-14 08:07:08
问题 I have several projects using NH and FNH to generate the mappings (some Fluent some Automapped). There are still some bugs and missing features i need, but it seems that FNH could die because of mapping-by-code integrated into NHibernate. Question: Contribute to FNH or to migrate the mappings to mapping-by-code or confORM and fixing problems/implementing features there? 回答1: At our office, we have been using NHibernate for 3 years now. We've been thinking about making a move to Fluent

Flunet Nhibernate all-delete-orphan not working like expected

随声附和 提交于 2020-01-06 10:43:53
问题 I have following domain classes: public class News: EntityBase { public virtual DateTime CreationDate { get; set; } public virtual IList<DomainNameToNews> DomainNameToNews { get; set; } public News() { DomainNameToNews=new List<DomainNameToNews>(); } } public class DomainNameToNews : EntityBase { public virtual DomainName DomainName { get; set; } public virtual News News { get; set; } } Mapping: public class NewsMap : ClassMap<News> { public NewsMap() { Id(x => x.Id).GeneratedBy.Identity();

Flunet Nhibernate all-delete-orphan not working like expected

白昼怎懂夜的黑 提交于 2020-01-06 10:41:52
问题 I have following domain classes: public class News: EntityBase { public virtual DateTime CreationDate { get; set; } public virtual IList<DomainNameToNews> DomainNameToNews { get; set; } public News() { DomainNameToNews=new List<DomainNameToNews>(); } } public class DomainNameToNews : EntityBase { public virtual DomainName DomainName { get; set; } public virtual News News { get; set; } } Mapping: public class NewsMap : ClassMap<News> { public NewsMap() { Id(x => x.Id).GeneratedBy.Identity();

Disabling caching in Fluent Nhibernate for a specific override

僤鯓⒐⒋嵵緔 提交于 2020-01-04 08:12:11
问题 We're using convention based mapping with Fluent NHibernate. The mapping looks like so: .Conventions.Add ( Table.Is(x => string.Concat(x.EntityType.Name.ToLower(), "s")), PrimaryKey.Name.Is(x => "Id"), DefaultLazy.Always(), DefaultCascade.SaveUpdate(), AutoImport.Never(), Cache.Is(x => x.ReadWrite()) ) For most of our objects this is perfect but on certain objects I wish to disable the 2nd level cache. However it doesn't appear that I can do this. There is no fluent option for Cache.None. I