fluent-nhibernate

Using MyGeneration with Fluent NHibernate

六眼飞鱼酱① 提交于 2019-12-07 11:33:14
问题 I found a fantastic template for NHibernate code generation using MyGeneration here, http://vucetica.blogspot.com/2009/01/nhibernate-template-for-mygeneration.html This creates XML mapping files with the extension hbm.xml. I was wonder if anybody knows of templates which support fluent NHibernate which defines the mapping using C# files. Thanks 回答1: When you are using Fluent NHiberate you needn't hbm files, you can generate them based on your domain model and conventions 来源: https:/

How to set custom DriverConnectionProvider with Fluent NHibernate

邮差的信 提交于 2019-12-07 11:14:33
问题 How to set custom DriverConnectionProvider with Fluent NHibernate? Best regards, Alexey Zakharov 回答1: I find solution. Here is the small sample, which how it could be done. Fluently.Configure() .Database(MsSqlConfiguration.MsSql2008 .ConnectionString(".......") .ShowSql() .Provider<TenantConnectionProvider>() ) public class TenantConnectionProvider : DriverConnectionProvider { public override IDbConnection GetConnection() { IDbConnection conn = Driver.CreateConnection(); try { conn

Working with Time Type in Fluent Nhibernate generates exception “Unable to cast object of type 'System.DateTime' to type 'NHibernate.Type.TimeType”

柔情痞子 提交于 2019-12-07 10:10:27
问题 I founded that NHibernate have several builtin Types that are not present in C# , but are present in some of SGBD. Now I have following: public class TimeSlot : EntityBase { public virtual NHibernate.Type.TimeType FromTime { get; set; } public virtual NHibernate.Type.TimeType ToTime { get; set; } } public class TimeSlotMap : ClassMap<TimeSlot> { public TimeSlotMap() { Id(c => c.Id).GeneratedBy.Identity(); Map(c => c.FromTime); Map(c => c.ToTime); } } In MSSQL this table look like in attached

How to make this thread-safe

ぐ巨炮叔叔 提交于 2019-12-07 08:08:29
问题 I have the following SessionFactory for Fluent NHibernate. I am getting an error of An invalid or incomplete configuration was used while creating a SessionFactory. with an InnerException of An item with the same key has already been added. This problem is only happening occasionally and my application works fine most of the time. Based on NHibernate: System.Argument Exception : An item with the same key has already been added I'm guessing my class is not thread-safe which would explain the

Using discriminator with Fluent NHibernate

て烟熏妆下的殇ゞ 提交于 2019-12-07 07:10:11
问题 I'm trying to create a discriminator column. This column would hold one of the many statuses available. Like my code will show, each status has a name as well as a background color. Each status shares the same base class. Here is my code: public class Item { public virtual int Id { get; set; } public virtual Status ItemStatus { get; set; } } public abstract class Status { private readonly int _id; public static readonly Status Foo = new FooStatus(1); public static readonly Status Bar = new

Why is Fluent NHibernate ignoring my unique constraint on a component?

匆匆过客 提交于 2019-12-07 06:19:53
问题 In my map I have: Component( x => x.ExposureKey, m => { m.Map(x => x.AsOfDate).Not.Nullable(); m.Map(x => x.ExposureId).Length(30).Not.Nullable(); } ).Unique(); The relevant output from the HBM is <component name="ExposureKey" insert="true" update="true" optimistic-lock="true" class="Some.Namespace.CreditExposureKey, Some.Namespace, Version=0.0.0.0, Culture=neutral, PublicKeyToken=aaaaaaaaaaaaaaaa"> <property name="AsOfDate" type="System.DateTime, mscorlib, Version=4.0.0.0, Culture=neutral,

Foreign Keys with SchemaExport in Fluent NHibernate using SQLite

杀马特。学长 韩版系。学妹 提交于 2019-12-07 06:15:39
问题 I am attempting to create a simple database application which keeps track of loans of various types of equipment using Fluent NHibernate and SQLite. However, when I try to generate the database structure with SchemaExport for use in unit testing, foreign keys for one-to-many relationships aren't created. Here is my Equipment entity: public virtual int Id { get; set; } public virtual EquipmentType Type { get; set; } public virtual int StockId { get; set; } And here are my mappings for

Fluent NHibernate - Configure Oracle Data Provider ODP

淺唱寂寞╮ 提交于 2019-12-07 06:14:06
问题 I am brand new to NHibernate and Fluent NHibernate and I am trying to get the following confguration to work. private static ISessionFactory CreateSessionFactory() { return Fluently.Configure() .Database( OracleDataClientConfiguration.Oracle10.ConnectionString("Data Source=mysource;User ID=myid;Password=mypwd;") ) .Mappings(m => m.FluentMappings.AddFromAssemblyOf<Program>()) .BuildSessionFactory(); } I have the Oracle.DataAccess assembly referenced. I am using VS 2010 and .Net 4 I get the

NHibernate DuplicateMappingException when mapping abstract class and subclass

倖福魔咒の 提交于 2019-12-07 06:05:28
问题 I have an abstract class and subclasses of this, and I want to map this to my database using NHibernate. I'm using Fluent and how to do the mapping. But when I add the mapping of the subclass an NHibernate.DuplicateMappingException is thrown when it is mapping. Why? Here are my (simplified) classes: public abstract class FieldValue { public int Id { get; set; } public abstract object Value { get; set; } } public class StringFieldValue : FieldValue { public string ValueAsString { get; set; }

Fluent nHibernate no identity column in table

大城市里の小女人 提交于 2019-12-07 05:24:07
问题 How do I specify with fluent NHibernate mapping for a table that doesn't have an identity column? I want something like this: public sealed class CustomerNewMap : ClassMap<CustomerNew>, IMap { public CustomerNewMap() { WithTable("customers_NEW"); Not.LazyLoad(); Not.Id(); // this is invalid... Map(x => x.Username); Map(x => x.Company); } } I mean no primary key defined in the database (not much defined in the database). 回答1: I found the answer to be: public CustomerNewMap() { WithTable(