fluent-nhibernate

How to query NHibernate for specific type?

泄露秘密 提交于 2019-12-24 01:46:07
问题 I'm using Fluent NHibernate with DiscriminateSubClassesOnColumn() to support subclassing. The column used to discriminate between subclasses is not mapped to an actual property on the entity. How do I create a query which returns only entities of a given type? Here's my try, where propertyName is the name of my discriminating column and value is the type name: return _db.CreateCriteria<T>() .Add(Restrictions.Eq(propertyName, value)) .List<T>(); However this gives me the error "could not

getting started with Fluent nHibernate and asp.net MVC

孤人 提交于 2019-12-24 01:26:13
问题 I thought of using Fluent nhibernate for data access with my asp.net mvc web application...Any good article that describes about the setup of Fluent nHibernate with asp.net MVC web application... 回答1: This series of articles is what I started with. I don't believe it's exactly what I ended up going with, but it's a good start. 来源: https://stackoverflow.com/questions/3011937/getting-started-with-fluent-nhibernate-and-asp-net-mvc

Why is Fluent NHibernate ignoring my convention?

断了今生、忘了曾经 提交于 2019-12-24 00:19:59
问题 I have a convention UserTypeConvention<MyUserType> where MyUserType : IUserType where MyUserType handles an enum type MyEnum . I have configured Fluent NHibernate thusly sessionFactory = Fluently .Configure() .Database(MsSqlConfiguration.MsSql2005.ConnectionString( c => c.Is(connectionString)) ) .Mappings( m => m .FluentMappings .AddFromAssemblyOf<A>() .Conventions .AddFromAssemblyOf<A>() ) .BuildSessionFactory(); where A is a type in the same assembly as UserTypeConvention<MyUserType> and

Fluent Nhibernate: Trying to create entity with composite key that is also the keys for two references

时光怂恿深爱的人放手 提交于 2019-12-24 00:16:12
问题 The references are unidirectional. The table (StoreProduct) for this entity is actually a join table that has these fields: Store_id Product_id ExtraBit So I went with an entity having a compoundID (store_id and product_id) and the ExtraBit is just a string: public class StoreProduct { protected StoreProduct():this(null,null,null){ } public StoreProduct(Store c_Store, Product c_Product, String c_ExtraBit) { Store = c_Store; Product = c_Product; ExtraBit = c_ExtraBit; } public virtual int

How do I get NHibernate to save an entity if I assign it an ID, but generate one otherwise?

半城伤御伤魂 提交于 2019-12-23 23:09:04
问题 According to the REST philosophy, a PUT request should update the resource at a URL if it exists, and create it if it doesn't exist. So in other words, if I use the following URL: PUT http://server/item/5 If an Item exists with an ID of 5, it will be updated. If an Item doesn't exist with an ID of 5, a new Item will be created with an ID of 5. However, I'm using NHibernate for persistence, and I mapped my IDs as Identity . This means that no matter what value I assign the ID, NHibernate will

FluentNHibernate Component.ColumnPrefix not being applied

拈花ヽ惹草 提交于 2019-12-23 20:24:02
问题 I recently upgraded FluentNHibernate from v1.1.0.685 to v1.2.0.712 (latest) for NHibernate 2.1 . My issue appears to be with classes that use the Component().ColumnPrefix() mapping. For example, public class Address{ public string Street {get; set;} public string Zip {get; set;} } public class AddressMap : ComponentMap<Address>{ Map( x => x.Street ); Map( x => x.Zip ); } public class PersonMap : ClassMap<Person> { public PersonMap(){ Id( x => x.Id ); Map( x=> x.Name ); Component( x => x

Castle Windsor, Fluent Nhibernate, and Automapping Isession closed problem

好久不见. 提交于 2019-12-23 19:28:38
问题 I'm new to the whole castle Windsor, Nhibernate, Fluent and Automapping stack so excuse my ignorance here. I didn't want to post another question on this as it seems there are already a huge number of questions that try to get a solution the Windsor nhib Isession management problem, but none of them have solved my problem so far. I am still getting a ISession is closed exception when I'm trying to call to the Db from my Repositories,Here is my container setup code. container.AddFacility

How should NHibernate update properties mapped as Version

感情迁移 提交于 2019-12-23 18:34:25
问题 Using fluent NHibernate I have a property on a class mapped using Version Version(x => x.Version); When I save the object, the Version property gets incremented in the database as I would expect, but the value of the property on the object only seems to change sometimes. using (var tx = session.BeginTransaction()) { session.Merge(item); tx.Commit(); item.Version; // Sometimes this is still 1, when I expect it to be 2. } The problem is then that if it remains as 1 and I make more changes and

How to cascade Save with CompositeId in NHibernate?

纵然是瞬间 提交于 2019-12-23 18:01:49
问题 I have a simple three table DB with many-to-many relation. A(id, Name) B(id, Name) AB(AId, BId) references A and B The corresponding classes: public class A { public virtual int Id { get; set; } public virtual string Name { get; set; } } public class B { public virtual int Id { get; set; } public virtual string Name { get; set; } } public class AB { public virtual A A { get; set; } public virtual B B { get; set; } public override bool Equals(object obj) { /* routine */ } public override int

How can I create a Fluent NHibernate Convention that ignores properties that don't have setters

孤街浪徒 提交于 2019-12-23 15:24:06
问题 I'm looking for a FluentNH (Fluent NHibernate) convention or configuration that ignores all properties that have no setter: It would still map these: public class foo{ public virtual int bar {get; private set;} } And omit these: public class foo{ public virtual int fizz{get;private set;} public virtual int bar{get {return fizz;}} //<------- } 回答1: You should use a custom mapping configuration public class DefaultMappingConfiguration : DefaultAutomappingConfiguration { public override bool