fluent-nhibernate-mapping

NHibernate fluent HasMany mapping inserts NULL Foreign key

℡╲_俬逩灬. 提交于 2019-12-22 06:34:15
问题 I have an entity Company that has many Orders. I mapped these as following to each other: Company HasMany(x => x.Orders).KeyColumn("CompanyID").Cascade.All().Inverse(); Order References(x => x.Company).Column("CompanyID") However when i create a new order for the company and try to save it, I get a SQL error: "Cannot insert the value NULL into column 'CompanyID', table 'Orders'; column does not allow nulls. INSERT fails." (this is the generated SQL statement: INSERT INTO Order (Name,

Fluent NHibernate References with constants

风流意气都作罢 提交于 2019-12-21 17:49:05
问题 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

Fluent Nhiberhate And Missing Milliseconds

本小妞迷上赌 提交于 2019-12-21 03:33:16
问题 I am using Fluent Nhibernate and Nhibernate for my current project. I need to record the time to the millisecond. I have this for my mapping Map(x => x.SystemDateTime) .CustomType("Timestamp") .Not.Nullable(); I genertaed the hbm.xml files and the line is the following: <property name="SystemDateTime" type="Timestamp"> <column name="SystemDateTime" not-null="true" /> </property> I have read this is the fix, but the records in the database do not have the milliseconds. Has anyone solved this

Fluent NHibernate to query stored procedure without an hbm.xml mapping

谁说胖子不能爱 提交于 2019-12-18 10:53:33
问题 Is there any way to query stored procedure in Fluent Nhibernate without creating an hbm.xml file mapping? 回答1: I assume you use the standard Session.GetNamedQuery(.... instead, you can use var result = Session.CreateSQLQuery("exec MyStoredProc :pUserId, :pIsLocked") .AddEntity(typeof(MyDomainObject)) .SetParameter("pUserId", userId) .SetParameter("pIsLocked", isLocked) .List<MyDomainObject>(); This allows you to call the stored proc but still get back a domain object (or list of) without

NHibernate.AssertionFailure: null identifier

半腔热情 提交于 2019-12-13 13:15:13
问题 Before I kick my computer in to next week... I've checked out every other question about this, but none of them have the solution. I've stripped this code right back, but it's still not working. I'm getting this error when saving an object: NHibernate.AssertionFailure: null identifier This is my mapping file: public class OrderMap : BaseMap<Order> { public SalesOrderMap() { Id(x => x.Id).Column("OrderId"); } } This is the entity: public class Order { public virtual int Id { get; protected set

How do I tell Fluent NHibernate to ignore specific properties without automapping?

时光毁灭记忆、已成空白 提交于 2019-12-12 13:42:02
问题 I am using Fluent NHibernate to map out an existing database. For this reason - automapping isn't an option for me. How do I tell NHibernate not to map certain properties? Many of them are read-only, and the others do not need to be persisted for other reasons. I am writing this in VB.Net. I get the typical error message: "The following types may not be used as proxies ... should be 'public/protected virtual' or 'protected internal virtual'" I have purposely not made my objects Overridable

Fluent NHibernate two levels Inheritance Issue

被刻印的时光 ゝ 提交于 2019-12-12 13:17:38
问题 I want to have Table per Type in one level and one Table for hierarchy in another level. Is it possible? description is here -> I have these classes: public class BaseItem { public int Id{ get; set; } } public class Item : BaseItem { } public class Child1 : Item { } public class Child2 : Item { } I wanna have tables for "BaseItem" and "Item" and not for "Child1" and "Child2" I try this mappings: public class BaseItemMap : ClassMap<BaseItem> { public BaseItemMap() { Id(p => p.Id).Column(

Fluent NHibernate One-To-Many Mapping

扶醉桌前 提交于 2019-12-12 08:32:59
问题 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

Fluent Nhibernate Mapping for Sql Views

不羁岁月 提交于 2019-12-12 07:48:45
问题 i am using Fluent Nhibernate in asp.net mvc3 with c# i am working in following way to generate and map a class Mapping using FluentNHibernate.Mapping; using Com.Web.Domain; namespace Com.Web.Mapping { public class CompanyMap : ClassMap<Company> { public CompanyMap() { Id(x => x.id); Map(x => x.Name); } } } Class using System.Collections.Generic; using System; namespace Com.Web.Domain { public class Company { public virtual int id { get; set; } public virtual string Name{get;set} } } and in

Fluent NHibernate Many-To-Many Mapping with 3 classes

江枫思渺然 提交于 2019-12-12 04:59:03
问题 First, I'm using NHibernate 3.2 and FluentNHibernate 1.3. I have 3 clasess: public class ClassA { public virtual Int32 Id{ get; } .... public ICollection<ClassB> ClassesB { get; } public ICollection<ClassC> ClassesC { get; } } public class ClassB { public virtual Int32 Id{ get; } .... public ICollection<ClassA> ClassesA { get; } public ICollection<ClassC> ClassesC { get; } } public class ClassC { public virtual Int32 Id{ get; } .... public ICollection<ClassA> ClassesA { get; } public