fluent-nhibernate

Best approach for building NHibernate DTO's

萝らか妹 提交于 2019-12-18 16:57:40
问题 I'm new to NHibernate (and ORMS) and trying to come to grips with the myriad of different options it presents. For reference, I'm using Fluent NHibernate with seperate business objects which in turn use DTO's purely for data access. My application architecture must support both windows and web "front ends". My quandry is one of general approach as there seem to be so many options. My DTO's look something like the sample below. Each DTO has a reference to an ISession which is passed to them

No session bound to the current context

て烟熏妆下的殇ゞ 提交于 2019-12-18 16:54:44
问题 I followed this tutorial: http://nhforge.org/blogs/nhibernate/archive/2011/03/03/effective-nhibernate-session-management-for-web-apps.aspx I am not getting a 'no session bound to the current context' error when trying to load a page (mvc 3). public static ISessionFactory BuildSessionFactory() { return Fluently.Configure() .Database(MsSqlConfiguration.MsSql2008 // .ConnectionString(@"Server=.\SQLExpress;Database=db1;Uid=dev;Pwd=123;") .ShowSql()) //.ExposeConfiguration(c => c.SetProperty(

ASP.NET MVC + fluent nNibernate, what IoC tool?

三世轮回 提交于 2019-12-18 13:17:43
问题 I'm working on a ASP.NET MVC project where we have decided to use Fluent nHibernate for dataccess. To enable loose coupling we go for a IoC/DI pattern. My questions is what IoC tool to go for. I've tried to find the differences between windsor, ninject, spring, structuremap and unity, but it's difficult to see the benefits each one has to offer. Whats your experience? 回答1: I use StructureMap and it's very easy to use. Personally I don't like to configure using xml and StructureMap makes it a

Implementing UnitOfWork with Castle.Windsor

纵然是瞬间 提交于 2019-12-18 10:46:15
问题 Simple question. How do I use UnitOfWork with Castle.Windsor, nHibernate, and ASP.NET MVC? Now for the extended details. In my quest to understand the UnitOfWork pattern, I'm having difficulty coming across anything that uses a direct example in conjunction with Castle.Windsor , specifically in regards to the way it needs to be installed. Here is my understanding so far. IUnitOfWork The IUnitOfWork interface is used to declare the pattern The UnitOfWork class must Commit and Rollback

NHibernate Eager loading multi-level child objects

人走茶凉 提交于 2019-12-18 10:23:09
问题 I have a hierarchy of objects, Order, Contact, Address: public class Order { public virtual Contact BillingContact { get; set; } } public class Contact { public virtual Address Address { get; set; } } I want to query an order by id, and eager load the billingcontact, along with it's address. var criteria = DetachedCriteria.For<Order>() .SetFetchMode("BillingContact", FetchMode.Eager) This criteria eager loads the BillingContact, but understandably not the address of the BillingContact. If i

fluent nhibernate component one-to-many

孤街醉人 提交于 2019-12-18 09:37:28
问题 I have couple of classes and want to map them correctly to database: public class A { public virtual Guid Id { get; private set; } public virtual ComponentClass Component { get; set; } } public class ComponentClass { public virtual IList<B> Elements { get;set; } } public class B { public virtual Guid Id { get; private set; } public virtual DateTime Time { get; set; } } I map them using fluent mappings like that: public class AMap : ClassMap<A> { public A() { Id(x => x.Id); Component(x => x

Custom SQL function for NHibernate dialect

醉酒当歌 提交于 2019-12-18 08:27:31
问题 I want to be able to call a custom function called "recent_date" as part of my HQL. Like this: [Date] >= recent_date() I created a new dialect, inheriting from MsSql2000Dialect and specified the dialect for my configuration. public class NordicMsSql2000Dialect : MsSql2000Dialect { public NordicMsSql2000Dialect() { RegisterFunction( "recent_date", new SQLFunctionTemplate( NHibernateUtil.Date, "dateadd(day, -15, getdate())" ) ); } } var configuration = Fluently.Configure() .Database(

Fluent code for mapping an IDictionary<SomeEntity, int>?

给你一囗甜甜゛ 提交于 2019-12-18 06:16:51
问题 I'm trying to figure out how to map an IDictionary property in fluent 1.0 RTM. From my understanding this translates to a ternary association. Example: class Bar { public IDictionary<SomeEntity, int> Foo {get; set;} } Bar.hbm.xml would then contain: <map name="Foo" table="BarFooTable"> <key column="..."/> <index-many-to-many class="SomeEntity" column="SomeEntity_Id"/> <element column="Value" type="int"/> </map> What would I have to write in fluent nhibernate to produce this mapping xml? The

Fluent NHibernate : How to map a 'Foreign Key' column in the mapping class

烈酒焚心 提交于 2019-12-18 05:29:17
问题 I'm starting to develop with Fluent NHiberate, and I was wondering how I create a defined 'Foreign Key' relationship in my Mapping class. Here's my class. These classes are a one-to-one with associated tables. public class Song { public virtual int SongID{ get; private set; } //Primary Key public virtual int SongArtistID { get; set; } //Foreign Key mapping to 'Artist.ArtistID' public virtual string Title { get; set; } } public class Artist { public virtual int ArtistID{ get; private set; } /

How to create composite UNIQUE constraint in FluentNHibernate?

天涯浪子 提交于 2019-12-18 05:28:33
问题 I know that I can Map(x => x.GroupName).WithUniqueConstraint() for a single property. But how do create a composite unique constraint in fluent nHibernate (where the unique constraint operates on the combination of two columns)? 回答1: In the latest version that I have used, it is UniqueKey("KeyName") that does this. Map(x => x.Something).UniqueKey("KeyName"); Map(x => x.SomeOtherThing).UniqueKey("KeyName"); 回答2: Use SetAttribute in your mapping file like so: Map(x => x.Something).SetAttribute(