fluent-nhibernate

Maintaining multiple one-to-many

巧了我就是萌 提交于 2019-12-04 06:42:46
问题 Following on from NHibernate one-to-one vs 2 many-to-one Is there an easy way to maintain multiple one-to-many relationships which are being used as a pseudo one-to-one. E.g. If I have 2 entities, User and Contact, which are related by a FK on each (User.ContactId and Contact.UserID). What is the best way to maintain that each reference points at the other. It would be wrong for the system to update User with a different contact, but the Contact still references User... 回答1: Most likely you

NHibernate: Map one class to two identical tables

此生再无相见时 提交于 2019-12-04 06:10:14
问题 I need to map one entity to two tables (Invoice and InvoiceHistory). It's not up to me to merge the two database tables in one and add a status column to differentiate them. The two tables have the exact same structure, but, as the name says, InvoiceHistory keeps a history of old invoices whereas Invoice stores active invoices. (the exact entity is not invoice but I am not allowed to disclose details plus I don't think they would be relevant anyway). 回答1: Create another entity which inherits

NHibernate Error Message: Invalid index 3 for this SqlParameterCollection with Count=3

ε祈祈猫儿з 提交于 2019-12-04 04:34:53
I have a test database design like this: The following is the pseudo-code: //BhillHeader public class BillHeader { public BillHeader() { BillDetails = new List<BillDetail>(); } public virtual int BillNo { get; set; } public virtual IList<BillDetail> BillDetails { get; set; } public virtual decimal Amount { get; set; } public virtual void AddDetail(BillDetail billdet) { BillDetails.Add(billdet); } } //BillHeader Map public class BillHeaderMap : ClassMap<BillHeader> { public BillHeaderMap() { Table("BillHeader"); LazyLoad(); Id(x => x.BillNo).GeneratedBy.Identity().Column("BillNo"); Map(x => x

FluentNHibernate: What is the effect of AsSet()?

岁酱吖の 提交于 2019-12-04 04:20:44
In Fluent Nhibernate what is the effect of specifying AsSet() on a HasMany or HasManyToMany relationship? Assuming the type of the mapped property is an Iesi Set, is there any difference between: HasMany(x => x.MySetProperty) .AsSet(); and HasMany(x => x.MySetProperty); Assuming your type is an Iesi Set, then there's no difference; the HasMany call on it's own is smart enough to figure out that you want a Set. The AsSet is a way to explicitly change your HasMany to a Set in situations where FNH might not be able to determine it by type, for example if you're exposing your collection as an

Why does Nhibernate share the session across multiple requests in my MVC application?

冷暖自知 提交于 2019-12-04 04:09:37
问题 We have an MVC project that constructs the NHibernate dependecies via StructureMap like this var sessionFactory = ConnectionRegistry.CreateSessionFactory<NHibernate.Context.WebSessionContext>(); For<ISessionFactory>().Singleton().Use(sessionFactory); For<INHibernateSessionManager>().Singleton().Use<NHibernateWebSessionManager>(); The ConnectionRegistry.CreateSessionFactory looks like this public static ISessionFactory CreateSessionFactory<T>() where T : ICurrentSessionContext { if (

Fluent NHibernate One-To-Many Mapping

旧街凉风 提交于 2019-12-04 03:54:14
I have the following 2 classes: Advert public virtual int Id { get; set; public virtual IList<AdvertImage> AdvertImages { get; set; } AdvertImage public virtual int Id { get; set; } public virtual string Filename { get; set; public virtual Advert Advert { get; set; } In the DB, my AdvertImages table has the FK 'AdvertId' which relates to the Adverts table which has the PK of 'Id'. This is a One-To-Many mapping, in that one advert can have many images. My Fluent NHibernate mappings (edited for brevity) are: AdvertMap Id(x => x.Id) .GeneratedBy.Identity(); ... HasMany(x => x.AdvertImages)

How do I do TDD efficiently with NHibernate?

女生的网名这么多〃 提交于 2019-12-04 03:47:10
It seems to me that most people write their tests against in-memory, in-process databases like SQLite when working with NHibernate. I have this up and running but my first test (that uses NHibernate) always takes between 3-4 seconds to execute. The next test runs much faster. I am using FluentNhibernate to do the mapping but get roughly the same timings with XML mapping files. For me the 3-4 second delay seriously disrupts my flow. What is the recomended way of working with TDD and NHibernate? Is it possible to mock ISession to unit test the actual queries or can this only be done with in

currentsessioncontext fluent nhibernate how to do it?

為{幸葍}努か 提交于 2019-12-04 03:35:34
I am trying to use fluent with session per request. I am following a "recipe" from nhibernate cookbook however it uses the nhibernate config file. I am not sure what is better but right now I am sticking with fluent config just because I would not know how to set the nhibernate config file to use fluent mapping and vanilla nhibernate mapping(hbm files). namespace Demo.WebUI { public class MvcApplication : NinjectHttpApplication { public static ISessionFactory SessionFactory { get; private set; } protected override void OnApplicationStarted() { SessionFactory = Fluently.Configure() .Database

Fluent NHibernate - How to map the foreign key column as a property

﹥>﹥吖頭↗ 提交于 2019-12-04 02:45:12
I am sure this is a straightforward question but consider the following: I have a reference between company and sector as follows: public class Company { public Guid ID { get; set; } public Sector Sector { get; set; } public Guid SectorID { get; set; } } public class Sector { public Guid ID { get; set; } public string Name { get; set; } } Ok. What I want is the SectorID of the Company object to be populated after I go: (new Company()).Sector = new Sector() { Name="asdf" } and do a flush. The mapping I am using kindly creates an additional column in the database called Sector_Id in the Company

mixing NHibernate with 3 tier developing

你离开我真会死。 提交于 2019-12-04 02:15:26
问题 I have a 3 tiered app: 1st layer: SQL DB. 2nd layer: App Sever (dotnet) 3rd layer: smart wpf client. I'm using NHibarnate (fluent) as the data source for the application server layer (App server- 2nd layer talks to DB using NH) Application layer talks to the client using WCF. Do I benefit anything from using NH - as WCF doesn't support NH lazy loading (at least it doesn't look like this) and - if I use a static session object - I have to make the server single instance single concurrency -