fluent-nhibernate

How to map composite primary key to foreign in fluent nhibernate?

ぃ、小莉子 提交于 2019-12-04 11:44:50
I have the following tables: table A: FOO (PK) | CLIENT (PK) table B: BAR (PK) | CLIENT (PK/FK) | FOO (FK) PK -> primary key FK -> foreign key There's a one-to-many relation between A and B. I can't simply do this: class AMap { public AMap() { CompositeId().KeyReference(a => a.FOO) .KeyReference(a => a.CLIENT); HasMany(a => a.B); } } class BMap { public BMap() { CompositeId().KeyReference(a => a.BAR) .KeyReference(a => a.CLIENT); References(a => a.A); } } It will fail with the following exception: Foreign key (FKE7804EB3DA7EBD4B:B [FOO])) must have same number of columns as the referenced

NHibernate mapping with a class hierarchy whose base class is abstract and the discriminator is not a string

大城市里の小女人 提交于 2019-12-04 11:39:07
问题 Here are the domain model classes: public abstract class BaseClass { ... } public class ChildClass : BaseClass { ... } Note that the parent class is abstract and this is what gives me some difficulties when comes the time to map with fluent nhibernate. My discriminator is a byte (tinyint in the DB). Because it is not a string and I can't manage to set a discriminator value on the base class, this does not work (taken from the mapping class for BaseClass): DiscriminateSubClassesOnColumn<byte>(

Latest Binary builds of FLuentNhibernate + Nhibernate + Linq for NHibernate

荒凉一梦 提交于 2019-12-04 11:36:05
do people build there own versions of all this? or is there a place to get all this prebuilt? I got the latest FluentNhibernate which has NHibernate but no Linq.... but I don't really want to setup a ruby rake build system etc etc unless I really really have to! Prefer to just get all the binaries I need. Here is a build: http://www.dennisdoomen.net/2009/07/nhibernate-210-ga-with-linq-and-fluent.html I build my own versions, because I don't want to be forced to upgrade all the dependencies of fluent when I just want to upgrade fluentnhibernate. Installing ruby is downloading and clicking one

Readonly Strategies with Nhibernate and Fluent Nhibernate

泪湿孤枕 提交于 2019-12-04 11:19:44
I been reading nhibernate for beginners 3.0 and been reading about common mistakes(a few of them I been making) I am wondering what are some strategies for making one or more records readonly. Right now I get all the rows back and loop through them making them readonly through session.Readonly(). I like in the book that they do with fluent class EntityMap : ClassMap<Entity> { public EntityMap() { SchemaAction.None(); ReadOnly(); // Mappings } } What I am not sure is what happens if I need these records to not be Readonly? To me this means I have to make this exact same mapping minus those 2

NHibernate.LazyInitializationException

好久不见. 提交于 2019-12-04 11:17:05
问题 We have been having this issue pop up sporadically, but now I can reproduce it every time. I am incrementing a view counter on my custom built forums, which causes an error: NHibernate.LazyInitializationException: failed to lazily initialize a collection, no session or session was closed This error occurs on another collection in the object. If I add: .Not.LazyLoad() To my Fluent mapping, the error shifts around my project. I kept disabling lazy loading on objects intil it going to a spot

Using custom type for the id property

China☆狼群 提交于 2019-12-04 11:08:53
I got the following classes: public class UserId { public UserId(int id){ //some validation } public override string ToString() {} } public class User { public UserId Id {get;set;} } How can I configure nhibernate/fluentnhibernate to use that class. The column is an int. as Diego mentioned it is not nessesaryly a good idea // UserMap Id(m => m.Id).CustomType<UserIdUserType>(); class UserIdUserType : IUserType { ... } 来源: https://stackoverflow.com/questions/9444056/using-custom-type-for-the-id-property

Fluent NHibernate - how to configure for oracle?

こ雲淡風輕ζ 提交于 2019-12-04 10:57:18
问题 Almost certainly a stupid question but I can't find the answer anywhere. In the Getting Started tutorial the database is SQLite and so his session factory creation is done using the SQLiteConfiguration class in the FluentNHibernate.Cfg.Db namespace Great! But I don't see a Configuration class for using an Oracle database. How do I do this? Cross-posted to the fluent NH mailing list (with answer) 回答1: This works for me. Hope this helps! private static ISessionFactory CreateSessionFactory() {

FluentNhibernate IDictionary<Entity,ValueObject>

对着背影说爱祢 提交于 2019-12-04 10:41:31
I had a mapping for a IDictionary<StocksLocation,decimal> property, this was the mapping: HasMany<StocksLocation>(mq => mq.StocksLocation) .KeyColumn("IDProduct") .AsEntityMap("IDLocation") .Element("Quantity", qt => qt.Type<decimal>()); Now i changed from decimal to a Value Object: Quantity . Quantity has two properties, decimal Value and Unit Unit (where Unit is an enum). I now have to map IDictionary<StocksLocation,Quantity> , how can i achieve this? Thanks in advance Daniel Schilling Option 1: Map it as an Entity I'm guessing that your table looks similar to this: CREATE TABLE Quantity (

Fluent NHibernate Self Referencing Many To Many

情到浓时终转凉″ 提交于 2019-12-04 10:38:15
问题 I have an entity called Books that can have a list of more books called RelatedBooks. The abbreviated Book entity looks something likes this: public class Book { public virtual long Id { get; private set; } public virtual IList<Book> RelatedBooks { get; set; } } Here is what the mapping looks like for this relationship HasManyToMany(x => x.RelatedBooks) .ParentKeyColumn("BookId") .ChildKeyColumn("RelatedBookId") .Table("RelatedBooks") .Cascade.SaveUpdate(); Here is a sample of the data that

How to fix a NHibernate lazy loading error “no session or session was closed”?

瘦欲@ 提交于 2019-12-04 10:30:05
I'm developing a website with ASP.NET MVC, NHibernate and Fluent Hibernate and getting the error " no session or session was closed " when I try to access a child object. These are my domain classes: public class ImageGallery { public virtual int Id { get; set; } public virtual string Title { get; set; } public virtual IList<Image> Images { get; set; } } public class Image { public virtual int Id { get; set; } public virtual ImageGallery ImageGallery { get; set; } public virtual string File { get; set; } } These are my maps: public class ImageGalleryMap:ClassMap<ImageGallery> { public