fluent-nhibernate

illegal attempt to associate a collection with two open sessions fluent nhibernate

白昼怎懂夜的黑 提交于 2019-12-12 12:14:01
问题 I have this exception "illegal attempt to associate a collection with two open sessions", it raises every time I save entity contains collection of children. I google it. I found that I opened two or more sessions when calling save, but I'm sure that I'm using only one session. Where I did wrong? How can I solve this problemn? Note: I'm using MVC4, and fluent NHibernate. Entities: public class Employee : EntityBase<int> { public Employee() : base() { Phones = new List<Phone>(); } public

PrimaryKeyNamingConvention Fluent Automapping

独自空忆成欢 提交于 2019-12-12 11:53:17
问题 I have a question about using PrimaryKeyNamingConvention Suppose the following class: public class banco { [Required] public virtual int banco_id { get; set; } ... } and public class PrimaryKeyNamingConvention : IIdConvention { public void Apply(IIdentityInstance instance) { instance.Column(instance.EntityType.Name + "_id"); } } and static AutoPersistenceModel CreateAutomappings() { ... Conventions.Setup(c => { c.Add<PrimaryKeyNamingConvention>(); }); You can use something like described

NHibernate; Deleting child deletes parent?

こ雲淡風輕ζ 提交于 2019-12-12 11:45:55
问题 Why is the parent (Store) deleted when I delete a child (Employee) ? I configure with convention Cascade.All . The user input sequence is quite simple: Start with empty database Add a parent Save, Load (Load = reload full object graph) Add a child Save, Load Delete Child Result: Empty database. (Parent deleted) It could be a basic mapping mistake, as it's my first take on NHibernate. I want Store to be the aggregate root , and thought that by not setting Inverse on the Store.Staff property,

nhibernate cache problem with linq queries

若如初见. 提交于 2019-12-12 10:56:09
问题 I am seeing some odd behavior from nhibernate caching and cannot understand the reasoning. I am not able to cache queries when doing select operations like query.Select(x=>x).ToList() but can cache when doing: var query = session.Linq<Promoter>(); var p = query.ToList(); Both produce the same sql query and should be doign the same thing. The following test explains the problem. [Test] public void Can_Use_Cache() { ISessionFactory factory = Storage.Application.Get<ISessionFactory>(

NHibernate mapping: UserTypes with many-to-one

独自空忆成欢 提交于 2019-12-12 10:11:43
问题 New to NHibernate and learning it as we are modifying an existing solution to use this ORM. Ideally, the storage structure and object classes need to stay the same, so Ive come across one or two mapping problems. One class 'Money' has a value and currency. The value is a double and the currency is a foreign key to a list table of currencies. Money can appear as a type on many objects/tables, so Ive created a CompositeUserType to map it along with a standard mapping to currency. This works

Fluent NHibernate mappings for localization

我与影子孤独终老i 提交于 2019-12-12 10:10:01
问题 I am trying to build a Database from NHibernate mappings and have run into a problem. I have many classes with localized string values: public class MyClass1 { public virtual int Id { get; set; } public virtual ShortString Name { get; set; } public virtual LongString Description { get; set; } } public class MyClass2 { public virtual int Id { get; set; } public virtual ShortString Name { get; set; } public virtual LongString Description { get; set; } } and Languages like public class Language

Fluent NHibernate - bind List<int>

余生颓废 提交于 2019-12-12 09:51:28
问题 I have a Class which looks something like this: public class User { public virtual int ID; public virtual string Name; public virtual IList<int> userRights; } I want to make a UserMap : ClassMap<User> Mapping the name is no problem however i cant seem to figure out how to map the userRights. Table looks like UserTable User_id int User_Name nvarchar User_group int UserRights User_group int RightID int How would you map this ? 回答1: Well if you want a List you need an index. So I would recommend

Fluent nHibernate , IDictionary Confusion

冷暖自知 提交于 2019-12-12 09:23:55
问题 Using the following classes.. public class Trait { public virtual int Id { get; set; } public virtual string Name { get; set; } } public class Sheet { public virtual int Id { get; set; } public virtual IDictionary<Trait, int> Influences { get; set; } } I have tried to map them using Fluent nHibernate, as such. public class TraitMap : ClassMap<Trait> { public TraitMap() { Id(x => x.Id); Map(x => x.Name); Table("Traits"); } } public class SheetMap : ClassMap<Sheet> { public SheetMap() { Id(x =>

Experience with fluent interfaces? I need your opinion!

笑着哭i 提交于 2019-12-12 08:56:03
问题 Sorry for this long question, it is flagged wiki since I'm asking for something that might not have a very concrete answer. If it is closed, so be it. My main question is this: How would you write a fluent interface that isn't fully defined in the base classes, so that programs that uses the fluent interfaces can tack on new words inside the existing structure, and still maintain a guiding interface so that after a dot, the intellisense only lists the keywords that actually apply at this

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