fluent-nhibernate

dynamic-component fluent automapping

不问归期 提交于 2019-12-05 02:10:41
问题 Does anyone know how can we automatically map dynamic components using Fluent Automapping in NHibernate? I know that we can map normal classes as components, but couldn't figure out how to map dictionaries as dynamic-components using fluent automapping. Thanks 回答1: We've used the following approach successfully (with FluentNH 1.2.0.712 ): public class SomeClass { public int Id { get; set; } public IDictionary Properties { get; set; } } public class SomeClassMapping : ClassMap<SomeClass> {

Fluent-NHibernate many-to-many cascade does not populate the link table

混江龙づ霸主 提交于 2019-12-05 02:09:29
OK, no matter how I define these mappings, my many-to-many mapping does not want to work with cascade insert. I have tried various combination of Cascade() with Reverse() and removing all unnecessary properties just to understand if they had anything to do with this not working, but no lock. It is really Simple stuff: I have a Message (like an email) which is sent from a user (I have called the entity BasicUser ) to a number of users (through property To ). User and Message in terms of recipients have a many-to-many relationship but FromUser has one-to-many. FromUser works fine and it is

NHibernate Image Storage - The length of the byte[] value exceeds the length configured

大城市里の小女人 提交于 2019-12-05 02:06:36
I am using Fluent NHibernate and am trying to store an image. Small images work, but larger images do not, and I receive this error when saving to the database (SQL Server): Exception: Error dehydrating property value for CFC.Domain.Vehicle.Image Inner Exception: The length of the byte[] value exceeds the length configured in the mapping/parameter. Here is my mapping: mapping.Table("Vehicle"); mapping.Id(x => x.Id, "VehicleID"); mapping.Map(x => x.Year).Not.Nullable(); mapping.Map(x => x.Image).CustomSqlType("VARBINARY(MAX)").Length(int.MaxValue); The "Image" property is a byte[]. Note the

Fluent NHibernate - Mapping a property to a column on a joined table

て烟熏妆下的殇ゞ 提交于 2019-12-05 01:46:18
问题 I've got a couple tables, for example: Product {Id, Name, ManufacturerId, ...} Manufacturer {Id, Name, ...} I'd like to be able to include ManufacturerName on my Product object (instead of having to load the whole Manufacturer row when I only need the name). My ProductMap looks like... Table("Product"); Id(x => x.Id, "Id"); Map(x => x.ProductName, "ProductName"); Map(x => x.ManufacturerId, "ManufacturerId"); References(x => x.Manufacturer, "ManufacturerId"); What do I need to add to populate

Null value objects in NHibernate

三世轮回 提交于 2019-12-05 01:34:27
I have a person entity containing an Address as a value object: public Person() { WithTable("Person"); Id(x => x.Id); Component<Address>(x => x.Address, a => { a.Map(x => x.Address1); a.Map(x => x.Address2); a.Map(x => x.Address3); a.Map(x => x.Town); a.Map(x => x.Postcode); }); } It states in the NHibernate docs that if all the properties of a value object (Address1, Address2 etc) are null, the entire component will be mapped as null (i.e. Person.Address will be null). This is giving me problems in cases where all address fields are null because in my pages where I might have (I'm doing ASP

Fluent nHibernate automapping property as nvarchar(max)

浪子不回头ぞ 提交于 2019-12-05 00:57:38
using fluent nhibernate, and automappings (nhibernate creates my db schema), how can i get nhibernate to create a nvarchar(max) column in the database based on the following class public class VirtualPage : BaseEntity { public virtual int ParentId { get; set; } public virtual string PageName { get; set; } public virtual string Title { get; set; } public virtual string Body { get; set; } public virtual string ViewName { get; set; } public virtual string ViewData { get; set; } // this must be nvarchar(max) } With automapping you can override the default length for text fields, but it will be

Fluent NHibernate automappings with self-reference

旧巷老猫 提交于 2019-12-05 00:24:02
问题 I have a simple class that looks like this... public class Item { public virtual int Id { get; set; } public virtual string Name { get; set; } public virtual int ParentId { get; set; } public virtual IList<Item> Children { get; private set; } public Item() { Children = new List<Item>(); } } ... where the Id is the primary key and ParentId is the foreign key. When I run this code I get Invalid object name 'ItemToItem'. exception and I can't figure out what's wrong? I seems like NHibernate

nHibernate HQL - entity is not mapped

為{幸葍}努か 提交于 2019-12-04 23:19:22
I have my nHibernate setup and working correctly with QueryOver for most queries, however, whenever I try to do a HQL CreateQuery I get the exception that the entity isn't mapped. I can confirm that the same entity works fine using QueryOver. Note: I am using fluent nHibernate Any ideas what would cause this? If you have disabled auto-import in your mappings ( <hibernate-mapping auto-import="false"> ), then you will have to use fully-qualified class names everywhere in your queries, unqualified class names won't work. Otherwise, enable auto-import. Conventions.Setup(x => { x.Add

How to add event listener via Fluent NHibernate?

痴心易碎 提交于 2019-12-04 22:50:51
I want to add an event listener ( IPreUpdateEventListener ) to add NHibernate but I can't seem to find an example when using a fluent configuration. I want to be able to add the listener when I create the session factory, e.g. when the following code is execute. _sessionFactory = Fluently.Configure() .Database(MsSqlConfiguration.MsSql2005.ConnectionString(connectionString).ShowSql()) .Mappings(m => m.FluentMappings.AddFromAssemblyOf<IEntity>()) .BuildSessionFactory(); Anyone know how to do this? Late answer, found your question when I was trying to do the same. Found a solution that should

Fluent NHibernate primary key constraint naming conventions

白昼怎懂夜的黑 提交于 2019-12-04 22:28:23
Is there any way to create a naming convention for my primary key constraints in Fluent NHibernate? I know you can name foreign key constraints, but it does not appear possible to name the primary key constraint. James Gregory from FNH says... No, that's not supported through NHibernate, so we can't support it either. http://groups.google.com/group/fluent-nhibernate/browse_thread/thread/9ea7155407d33772 来源: https://stackoverflow.com/questions/1358043/fluent-nhibernate-primary-key-constraint-naming-conventions