fluent-nhibernate

Fluent-Nhibernate References and PropertyRef Doing a Select With Lazy Load

耗尽温柔 提交于 2019-12-19 04:06:24
问题 I am using PropertyRef for one of my References properties. With LazyLoad() it still does a Select and loads the User entity, even though I never "hit" the SalesPerson property. Order Mapping Id(x => x.Id).GeneratedBy.Native(); References(x => x.SalesPerson) .LazyLoad() .PropertyRef(x => x.Username) .Column("rsm"); Map(x => x.Title); Order Class public class Order : BaseEntity { ... public virtual User SalesPerson { get; set; } public virtual string Title { get; set; } ... } User Mapping Id(x

NHibernate Validator not integrating with Fluent NHibernate

左心房为你撑大大i 提交于 2019-12-19 04:03:30
问题 I'm having some trouble getting NHV to work with Fluent NHibernate. A unit test that I have that has an entity that SHOULD be failing validation ends up throwing an ADO exception. I have NHV configured the following way: private static void Init() { _SessionFactory = Fluently.Configure() .Database(MsSqlConfiguration.MsSql2005.ConnectionString(connectionString) .ShowSql()) .Mappings(m => m.FluentMappings.AddFromAssemblyOf<SessionFactory>() .ExportTo(pathToExportMappingsTo))

Using Multiple databases in Fluent Nhibernate, System.TypeInitializationException was unhandled

邮差的信 提交于 2019-12-19 03:31:25
问题 I was trying to implement Multiple DB connected Fluent NHibernate sample Application. My Fluent NHibernate Repository is as follows: namespace RepositoryExample.Repository.NHibernate { public class NHibernateRepository<T> : IRepository<T> where T : class { protected static Configuration config; private static readonly ISessionFactory _globalSessionFactory = new Configuration().Configure().BuildSessionFactory(); protected static IDictionary<string, ISessionFactory> _allFactories; public

Prevent Fluent NHibernate select n+1

我与影子孤独终老i 提交于 2019-12-19 03:19:01
问题 I have a fairly deep object graph (5-6 nodes), and as I traverse portions of it NHProf is telling me I've got a "Select N+1" problem (which I do). The two solutions I'm aware of are Eager load children Break apart my object graph (and eager load) I don't really want to do either of these (although I may break the graph apart later as I forsee it growing) For now.... Is it possible to tell NHibernate (with FluentNHibernate) that whenever I try to access children, to load them all in one go,

NHibernate sets Foreign Key in secondary update rather than on initial insert violating Not-Null Constrain on key column

送分小仙女□ 提交于 2019-12-19 03:04:07
问题 I am having a problem with what should be a fairly simple (I would think) NHibernate use case. I have a classic Parent and a Child entity like so: public class Parent { public virtual int ParentId { get; set; } public virtual string Name { get; set; } public virtual IList<Child> Children { get; set; } } public class Child { public virtual int ChildId { get; set; } public virtual Parent Parent { get; set; } public virtual string Name { get; set; } } And mappings as follows: public class

NHibernate sets Foreign Key in secondary update rather than on initial insert violating Not-Null Constrain on key column

时间秒杀一切 提交于 2019-12-19 03:04:06
问题 I am having a problem with what should be a fairly simple (I would think) NHibernate use case. I have a classic Parent and a Child entity like so: public class Parent { public virtual int ParentId { get; set; } public virtual string Name { get; set; } public virtual IList<Child> Children { get; set; } } public class Child { public virtual int ChildId { get; set; } public virtual Parent Parent { get; set; } public virtual string Name { get; set; } } And mappings as follows: public class

How do you map an entity -> interface relationship using Fluent NHibernate?

大兔子大兔子 提交于 2019-12-19 02:21:07
问题 given the following class definition: public class Order { public IProduct Product {get;set;} } I have this (fluent) mapping References(x=>x.Product, "ProductId"); And get this exception: An association from the table Orders refers to an unmapped class, which makes sense because it doesn't know what implementation I will pass to it. I understand why I have to define the type in the mapping (IProduct could be anything) but I'm not sure how to do it. Thanks, Kyle 回答1: Try mapping the interface

what does inverse and cascade means in NHibernate

寵の児 提交于 2019-12-18 21:26:15
问题 I'm learning Fluent Nhibernate and my question is: What does Inverse mean? I read that it means that the other side of the relationship is responsible for the saving, and so does Cascade , Can someone please explain what are the differences between them? Please explain in details because I'm a newbie at NH. 回答1: Have a look at this text (link down, here's a mirror on archive.org) , the "inverse" attribute is explained in detail. The different cascade options are well explained by Ayende

Fluent NHibernate “Could not resolve property”

纵然是瞬间 提交于 2019-12-18 18:54:33
问题 I have read a lot of the questions about that same error but none since to match my exact problem. I'm trying to access the property of an object, itself part of a root object, using Fluent NHibernate. Some answers say I need to use projections, others that I need to use join, and I think it should work through lazy loading. Here are my two classes along with the Fluent mappings: Artist class public class Artist { public virtual int Id { get; set; } public virtual string Name { get; set; }

Fluent NHibernate enforce Not Nullable on Foreign Key Reference

≡放荡痞女 提交于 2019-12-18 17:07:22
问题 Just getting my feet wet with some Fluent NHibernate AutoMap conventions, and ran into something I couldn't figure out. I assume I'm just not looking in the right place... Basically trying to enforce NOT-NULL on the "many" side of the one to many relationship. It seems, using the automapping, it always makes the parent property Id nullable in the database. I did some searching on StackOverFlow and found similar questions, but nothing relating to AutoMapping and Conventions though (unless I