fluent-nhibernate

Fluent NHibernate inheritance mapping problem

和自甴很熟 提交于 2019-12-07 23:49:22
问题 I am using Fluent NHibernate with table per subclass inheritance mapping. I want to reference to a list of specific objects, but i can't figure out, how to restict the result to objects of one specific class. class PetMap : ClassMap<Pet> { public PetMap() { Id(c => c.ID).GeneratedBy.Identity(); } } class DogMap : ClassMap<Dog> { public DogMap() { Mac(c => c.DogSpecificProperty); } } class CatMap : SubclassMap<Cat> { public CatMap() { Mac(c => c.CatSpecificProperty); } } class PersonMap :

NHibernate or FluentNHibernate or ActiveRecord?

时光总嘲笑我的痴心妄想 提交于 2019-12-07 21:15:24
问题 I am in a stage of mapping my CSharp classes into database tables. I have decided to use NHibernate as my ORM tool after comparing with other tools. I have never done a real project with NHibernate before and now am considering alternatives for the mapping, ActiveRecord: according to the project's web site, using ActiveRecord can boost productivity dramatically. However, I do not like the idea of adding attributes to my CSharp classes. After all, my class should NOT have any knowledge of

fluent NHibernate one-to-one relationship?

对着背影说爱祢 提交于 2019-12-07 21:06:00
问题 I have a problem with one-to-one relationships in the fluent nHibernate. I have the following relational table from the AdventureWorks2008 database. BusinessEntity (Table) BusinessEntityId Int (PK, Identity) Person (Table) BusinessEntityId int (PK, Reference with BusinessEntity table) FullName varchar(255) The relationship between BusinessEntity table and Person table is one-to-one. How do I map fluently without any extra field like "Id" in the Person table? There should be 2 class one for

How to map this in Fluent.NHibernate

随声附和 提交于 2019-12-07 19:25:50
问题 I'd like to get this output from fluent.nhibernate <map name="Dict" table="TABLE"> <key column="ID_USER" /> <index-many-to-many column="ID_TABLE" class="TableClass" /> <element column="COL" type="Int32" /> </map> where class has: public class User { public virtual IDictionary<TableClass, int> Dict { get; protected set; } } Closest I've got to is this: HasMany(x => x.Dict) .Table("TABLE") .KeyColumn("ID_USER") .AsMap<TableClass>("ID_TABLE") .Element("COL"); And the output for that is: <map

Reference parent table alias in Fluent NHibernate ClassMap Formula?

对着背影说爱祢 提交于 2019-12-07 18:00:34
Is it possible to reference or rename an entity's table alias in a Fluent NHibernate Formula? I can usually use "this_" but that unfortunately does not seem to be consistent based on the number of other aliases NHibernate generates. this.Map(x => x.IsLocked).Formula("CASE WHEN (SELECT COUNT(*) FROM dbo.Child c WHERE c.InboundDate >= BeginDate AND c.InboundDate < EndDate) > 0 THEN 1 ELSE 0 END"); This gets me by but I run into trouble when I need to match of identically named fields, (like "ID.") this.Map(x => x.IsLocked).Formula("CASE WHEN (SELECT COUNT(*) FROM dbo.Child c WHERE c.ID = ID) > 0

trying to implement session per web request, No current session context configure

帅比萌擦擦* 提交于 2019-12-07 16:54:11
问题 As I said in the title I want to implement session per web request. My session provider is configured like this (I'm not interested in changing this conf.) public class SessionProvider { public static SessionProvider Instance { get; private set; } private static ISessionFactory _SessionFactory; static SessionProvider() { var provider = new SessionProvider(); provider.Initialize(); Instance = provider; } private SessionProvider() { } private void Initialize() { string csStringName =

Fluent NHibernate: override derived classes not in the base class auto-mapping

杀马特。学长 韩版系。学妹 提交于 2019-12-07 16:41:10
问题 The story: I had class User and class Organization: User. I did not use any mappings for these classes, let FNH do mapping automatically. Then, I added public class OrganizationMap : IAutoMappingOverride<Organization> { public void Override(AutoMap<Organization> mapping) { } } Notice there're no overrides. So I did not expect any changes in FNH behavior. But I got this (during schema export actually): NHibernate.MappingException: (XmlDocument)(2,4): XML validation error: The element 'class'

Handling a one-to-many relationship with value types in Fluent NHibernate

谁说我不能喝 提交于 2019-12-07 13:21:52
问题 I'm working on migrating an application to NHibernate, and I'm using Fluent NHibernate. I'm running into an issue mapping a collection of value types to an aggregate root. I have a PhoneNumber value type that has a few properties — Number , NumberType , and Description . There are a number of objects in my domain that have collections of phone numbers. In the database (SQL 2008), these values are held in different tables. So I might have Customers and CustomerPhoneNumbers as well as Vendors

How to Specify Columntype in fluent nHibernate?

心已入冬 提交于 2019-12-07 12:21:09
问题 I have a class CaptionItem public class CaptionItem { public virtual int SystemId { get; set; } public virtual int Version { get; set; } protected internal virtual IDictionary<string, string> CaptionValues {get; private set;} } I am using following code for nHibernate mapping Id(x => x.SystemId); Version(x => x.Version); Cache.ReadWrite().IncludeAll(); HasMany(x => x.CaptionValues) .KeyColumn("CaptionItem_Id") .AsMap<string>(idx => idx.Column("CaptionSet_Name"), elem => elem.Column("Text"))

Fluent NHibernate exception moving objects between collections

对着背影说爱祢 提交于 2019-12-07 12:08:51
问题 When moving an object from one collection to another and when cascade is set to all-delete-orphan, I get the following exception: deleted object would be re-saved by cascade (remove deleted object from associations) I thought that nhibernate would not delete an object when it is referenced in another collection when you use all-delete-orphan. Can anyone confirm that, when you have objects like Folders which contain Folders or Files and you move a File from one Folder to another, you should