fluent-nhibernate

How to specify table name in Fluent NHibernate ClassMap class?

会有一股神秘感。 提交于 2019-12-05 08:29:33
问题 I am newbie to NHibernate and trying to use Fluent for mapping. My entity class name is different from the database table name it has to be mapped to. I am using mapping class derived from ClassMap<> , but I can't specify the table name: the property TableName from ClassMap is read-only. Thanks for your help. 回答1: Use Table("table_name") instead. 回答2: Does it work like? public class UserAccountMap : ClassMap<UserAccount> { public UserAccountMap() { Table("User"); Id(x => x.UserID, "UserID")

What are the differences between HasOne and References in nhibernate?

岁酱吖の 提交于 2019-12-05 08:27:35
问题 What are the differences between HasOne() and References() in nhibernate? 回答1: HasOne creates a one-to-one mapping between tables for you. References creates a typical relational many-to-one relationship. More defined: a one-to-one relationship means that when one record exists in one table, it must (or can) have one and at most one record in the other referenced table. Example: User table and Options table (one user has one fixed set of options) a many-to-one relationship means that when one

Mapping custom enum classes with Fluent Nhibernate

♀尐吖头ヾ 提交于 2019-12-05 08:16:13
Reading some posts from Jimmy Boggard and wondering - how exactly is it possible to map those beasts with fluent nhibernate? How mapping would look like for this? public class EmployeeType : Enumeration{ public static readonly EmployeeType Manager = new EmployeeType(0, "Manager"), Servant = new EmployeeType(1, "Servant"), AssistantToTheRegionalManager = new EmployeeType (2, "Assistant to the Regional Manager"); private EmployeeType() { } private EmployeeType(int value, string displayName) : base(value, displayName) { } } Ah... it was easy. In CodeCampServer - there's a generic EnumerationType

How do you ignore/persist values in MVC when your view-model doesn't have as many fields as your domain model?

五迷三道 提交于 2019-12-05 07:43:05
I have a site where I'm using fluentNhibernate and Asp.net MVC. I have an Edit view that allows user to edit 8 of the 10 properties for that record (object). When you submit the form and the Model binds, the two un-editable fields come back in the view-model as Empty strings or as default DateTime values depending on the type of property. Because I'm also using AutoMapper to map my view-model to my Domain Entity, I cannot just load a fresh copy of my object from the database and manually set the 2 missing properties. Whats the best way to persist those fields that I don't want edited? One way

Need help with NHibernate / Fluent NHibernate mapping

我的未来我决定 提交于 2019-12-05 07:22:44
问题 Let's say your have the following table structure: ============================== | Case | ============================== | Id | int | | ReferralType | varchar(10) | +---------| ReferralId | int |---------+ | ============================== | | | | | | | ====================== ====================== ====================== | SourceA | | SourceB | | SourceC | ====================== ====================== ====================== | Id | int | | Id | int | | Id | int | | Name | varchar(50) | | Name

NHibernate: System.Argument Exception : An item with the same key has already been added

折月煮酒 提交于 2019-12-05 04:51:28
I'm getting a sporadic error that is difficult to reproduce. My first guess is that somehow I have a leaking nhibernate session, however when I ran the nhibernate profiler , I didn't see much out of the ordinary. MVC 2.0 Fluent version 1.1.0.685 NHibernate version 2.1.2.4000 Exception: System.ArgumentException : An item with the same key has already been added. Stack Trace: at System.Collections.Generic.Dictionary 2.Insert(TKey key, TValue value, Boolean add) at NHibernate.Util.ThreadSafeDictionary 2.Add(TKey key, TValue value) at NHibernate.SqlTypes.SqlTypeFactory.GetTypeWithLen[T](Int32

How can I Change the default scale and precision of decimals in Fluent NHibernate?

末鹿安然 提交于 2019-12-05 03:23:39
In the application I'm building, I have many decimal fields with a specific precision and scale that need to be mapped from a database. I can achieve this by using the Precision() and Scale() methods: public class ClassAMap : ClassMap<ClassA> { public ClassAMap () { Map(x => x.Value).Precision(22).Scale(12); } } Is there any way to change the default precision and scale for decimals, so I don't need to remember to add the calls to Precision() and Scale() for every decimal mapped? You can define a PropertyConvention. Following is the general idea. (NOT tested) public class DecimalConvention :

How to solve this exception “Could not find a setter for property 'ProductCode' in class … ”

∥☆過路亽.° 提交于 2019-12-05 03:21:34
I am getting the following exception: "Could not find a setter for property 'ProductCode'in class ...OrderItem.class " The property (ProductCode) is one of my table keys. see how is the property declaration in the class. public class OrderItem : EntityBase { public virtual short Company { get; set; } public virtual int Order { get; set; } public virtual string Seri { get; set; } public virtual string ProductCode { get; set; } public virtual string Crop { get; set; } . . . } below this my mapping. public MapOrderItem() { Table("IPED"); CompositeId() .KeyProperty(c => c.Company, "C_EMP")

NHibernate / Fluent NHibernate Dynamic Column Mapping

≯℡__Kan透↙ 提交于 2019-12-05 02:40:56
问题 I have a table that, some of its columns are unknown at compile time. Such columns could either be of an integer value, or some Enum value. There is a table that holds all the names of such dynamic columns and also holds the column's type. This "metatable" has the following columns: DynamicColumnId (Pk) Name TypeId (Integer / Enum, as Fk from a separate table) Integer columns have the Name from this table, whereas Enum columns are Fk columns from a table that has that Name , with some

Most painless multi-tenancy implementation using ASP.NET, NHibernate / Fluent NHibernate

牧云@^-^@ 提交于 2019-12-05 02:24:33
问题 I'm trying to implement multi-tenancy in an ASP.NET MVC application I have, that uses NHibernate. Though I have control over the database for multi-tenancy. I'm trying to figure out the best way to filter our database queries using NHibernate. I would like to know if there is a painless way where I can append a condition (something like WHERE InstanceID = 1 ) to every CRUD query to the DB using NHibernate. I looked at global filters. But I wasn't sure if I'm using it the right way. I tried