fluent-nhibernate

Fluent NHibernate References with constants

不想你离开。 提交于 2019-12-04 10:02:20
I have a table mapped in Fluent NHibernate. This table must join to another table on an ID, but must also filter the joined values on that table against a set of constant values. Consider the following SQL: SELECT * FROM Table1 INNER JOIN Table2 ON Table1.Table2Id = Table2.Id AND Table2.Category = 'A constant expression' AND Table2.Language = 'A constant expression' My fluent mapping for Table1 currently looks like this: References(a => a.Table2).Nullable().Columns("Table2Id").ReadOnly(); How can I implement the constant expressions? I have noticed that your mapping specifies Nullable and no

Fluent NHibernate - HasMany().WithKeyColumnName

那年仲夏 提交于 2019-12-04 09:25:11
I just got the latest version of Fluent from Google code and it seems some of the mapping has changed since I last used it. Previously I could Map a relationship using the following when the id I was joining on had a different name in the second table HasMany(x => x.Roles).WithTableName("tbl_Roles").WithKeyColumn("RoleId"); How is done in the latest release of Fluent? Thanks HasMany(x => x.Roles) .WithTableName("tbl_Roles") .KeyColumns.Add("RoleId"); Multiple column support was added, so the method signature needed to be improved to make it clear what's happening. bezieur This works for me:

NHibernate throwing Session is closed

 ̄綄美尐妖づ 提交于 2019-12-04 09:04:10
I'm flapping in the wind, so I thought I'd ask here... Please let me know if this is obvious and has been answered before. I'm building an MVC 3 site which works fine while I'm running it with one user, where I click through the pages. However, if I madly hit refresh, eventually I hit a "Session is closed". I've isolated out almost all of all my repository to try to get to the bottom, so I know have it erroring on the homepage. The only thing that is being called in the repository is get the user's name from a database table. I'm using Postgres as a database, and the ASP.NET Membership

fluent nhibernate r1.0 fluent mapping disable lazy load

僤鯓⒐⒋嵵緔 提交于 2019-12-04 08:47:40
问题 how to disable lazy loading in fn r1.0? 回答1: Fluently.Configure() .Database( SQLiteConfiguration.Standard .InMemory) .Mappings( m => m.AutoMappings .Add( AutoMap.AssemblyOf<_Field>() ) ) .Conventions .Add( FluentNHibernate.Conventions.Helpers.DefaultLazy.Never() ) .BuildSessionFactory(); 回答2: You can try with: Not.LazyLoad(); inside your mapping constructor. 回答3: Like this: References(x => x.Something).Not.LazyLoad(); 来源: https://stackoverflow.com/questions/1412002/fluent-nhibernate-r1-0

Fluent NHibernate entity HasMany collections of different subclass types

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-04 08:26:52
问题 So everything is working well with the basic discriminator mapping. I can interact directly with entities A and B without any problems. public class BaseType {} public class EntityA : BaseType {} public class EntityB : BaseType {} This maps without drama in the BaseType mapping as DiscriminateSubClassesOnColumn<string>("Type") .SubClass<BaseType>("A", m => { }) .SubClass<BaseType>("B", m => { }); The problem occurs when: in an aggregate we want to map collections to each subclass Using

one-to-one fluent nhibernate?

冷暖自知 提交于 2019-12-04 08:20:02
Is it possible yet to do a one-to-one mapping with fluent nhibernate? I have the following as part of an hbm that I'm trying to convert to fluent: <one-to-one name="Person" property-ref="FileData" constrained="true"/> I see a OneToOnePart<OTHER> in the code but i'm not sure how or if this is used to accomplish this. Thanks! There is a HasOne mapping map => map.HasOne(x => x.Person) .PropertyRef(x => x.FileData) .Constrained(); I think that's what you're looking for. 来源: https://stackoverflow.com/questions/579414/one-to-one-fluent-nhibernate

How to set “cascade delete” option to “Set Null” in Fluent NHibernate?

淺唱寂寞╮ 提交于 2019-12-04 08:15:27
I am new to Fluent nHibernate and would like to know, if I have two classes Profile and Email mapped one-to-many as following... I want to define a nHibernate mapping fluently so when Profile is deleted, Email will remain in the DB, with a key set to Null. Or in other words to have "ON DELETE SET NULL" ALTER TABLE [dbo].[Email] WITH CHECK ADD CONSTRAINT [FK4239B252F6539048] FOREIGN KEY([ProfileId]) REFERENCES [dbo].[Profile] ([Id]) ON UPDATE SET NULL ON DELETE SET NULL Any help is greately appreciated! public sealed class ProfileMapping : ClassMap<Profile> { public ProfileMapping() { // Some

How to set a configuration property when using fluent nhibernate?

社会主义新天地 提交于 2019-12-04 08:03:51
In particular, I'd like to set current_session_context_class . I know how to do it in hibernate.cfg.xml, but is it possible at all with pure fluent configuration? You can use the method ExposeConfiguration on a FluentConfiguration instance, to access the original NHibernate Configuration object. Then, you'll have access to the Properties property, and you will be able to add the current_session_context_class one. Here is a the pseudo-code: Fluently.Configure() .Database(SQLiteConfiguration.Standard.InMemory) .ExposeConfiguration(c => { c.Properties.Add("current_session_context_class", typeof

NHibernate Fluent Add external Assembly mappings

落爺英雄遲暮 提交于 2019-12-04 06:49:24
问题 I have a project with my mappings and entities stored in other class libraries and NHibernate layers in another project. In my testing project I would like to add these mapping via fluently configure... Mappings... via assebly and not individually. In my code below you can see I added just one entity.. But I would like to configure it to scan my other assemblies. I am sure I am just missing the obvious here.. any pointers would be greatly appreciated... [Test] public void Can_generate

Lazy loading for NHibernate with Ignore.NotFound

牧云@^-^@ 提交于 2019-12-04 06:47:35
I have a mapping like the bellow for a Candidate object: References(x => x.Country).Column("CountryId").NotFound().Ignore() the problem here is, if I select * Candidates I get a extra select for each of them, not a good thing, so I pull out the NotFound().Ignore() bit but now the following code fails with ObjectNotFoundException exception: if (entity.Country != null) { bos.CountryName = entity.Country.Name; } Is there a way to force Hhibernate do the select when I compare County != null ? Thank you, When you specify the .NotFound().Ignore() this forces the entity to be eagerly loaded and