fluent-nhibernate

Fluent nhibernate mapping problem: many to many self join with additional data

有些话、适合烂在心里 提交于 2019-12-06 08:34:18
问题 I am struggling with mappings for the following sql tables |Post | |PostRelation | |------------------| |-----------------| |PostId |1--------*|ParentPostId | |---other stuff--- |1--------*|ChildPostId | | | |RelationType | Ideally Id like a property on post called relatedPosts as Dictionary <RelationType,IList<Post>> But at the minute Id just settle for a property on post with an IList<PostRelation>. I successfully used a many to many to get related posts, but this method loses the addtional

Why does this HQL delete fail, when an HQL select with same terms works?

一笑奈何 提交于 2019-12-06 08:32:46
问题 Why does the following HQL query fail? string hql = @"delete MyLog log where log.UtcTimestamp < :threshold and log.Configuration.Application = :application"; session.CreateQuery(hql) .SetDateTime("threshold", threshold) .SetEnum("application", this.application) .ExecuteUpdate(); The same form of query works when used in a select: string hql = @"from MyLog log where log.UtcTimestamp < :threshold and log.Configuration.Application = :application"; IList<MyLog> log = session.CreateQuery(hql)

Nhibernate stores id=0 as null

僤鯓⒐⒋嵵緔 提交于 2019-12-06 08:18:55
问题 I have small problem with nHibernate (fluent) I have two objects, one contains another - a parent and a child (predefined objects, readonly). mappings: public class ParentClass { public virtual int Id { get; set; } public virtual ChildClass Metoda { get; set; } } public ParentClassMap() { Table("Wyceny"); Id(x => x.Id).Column("Id").GeneratedBy.TriggerIdentity(); References(x => x.Metoda).Column("RMW_ID"); } public ChildClass { public virtual int Id { get; set; } public virtual string Nazwa {

Fluent mapping - entities and classmaps in different assemblies

不羁的心 提交于 2019-12-06 07:36:44
问题 When using fluent configuration to specify fluent mappings like this: .Mappings(m => m.FluentMappings.AddFromAssembly(typeof(UserMapping).Assembly)) At the moment I am getting a "NHibernate.MappingException : No persister for" error. Is it a problem that my Entities and my ClassMaps are in different assemblies? Presumably AddFromAssembly is interested in the assembly that holds the class maps, not the entities? (that is what I have assumed) Thanks! UPDATE: Sorry for not responding to answers

Map to a list of Enums?

亡梦爱人 提交于 2019-12-06 07:22:45
问题 I need to map a class which has a list of Enums to a db table, using NHibernate here are the objects public class Driver : IIdentity { private IList<Licence> licences; /// <summary> /// The drivers licences /// </summary> public virtual IList<Licence> Licences { get { return this.licences; } set { this.licences = value; } } ..... rest of the class .... } //the enum public enum Licence { FivePersonCar = 5, SixPersonCar = 6 } ---------------- here is the DB table TABLE [dbo].[DriverLicence](

NHibernate mapping: UserTypes with many-to-one

泪湿孤枕 提交于 2019-12-06 07:16:37
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 fine, but for the life of me I cannot get the currency relationship to lazy load from NHibernate. We use

NHibernate Save Is Trying to Clear Child KeyColumn Id On Update

流过昼夜 提交于 2019-12-06 06:31:20
I am trying to create a parent object that has multiple children in a 1 to many relationship. I am not referencing the Parent object on the child object, instead I am mapping its keycolumn as a field. When I try to save this object for the first time, it works as expected without any issues (cascading all the Id's and children). When I try to get the object from the database, update some properties on it and re-save it again, it fails. The actual error message I am getting is "Could not delete collection". The error above is due to the fact that it is trying to set the "ParentId" field on the

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

社会主义新天地 提交于 2019-12-06 06:30:47
问题 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

How to map this in Fluent.NHibernate

♀尐吖头ヾ 提交于 2019-12-06 06:02:17
I'd like to get this output from fluent.nhibernate <map name="Dict" table="TABLE"> <key column="ID_USER" /> <index-many-to-many column="ID_TABLE" class="TableClass" /> <element column="COL" type="Int32" /> </map> where class has: public class User { public virtual IDictionary<TableClass, int> Dict { get; protected set; } } Closest I've got to is this: HasMany(x => x.Dict) .Table("TABLE") .KeyColumn("ID_USER") .AsMap<TableClass>("ID_TABLE") .Element("COL"); And the output for that is: <map name="Dict" table="TABLE"> <key> <column name="ID_USER" /> </key> <index type="TableClass"> <column name=

Readonly Strategies with Nhibernate and Fluent Nhibernate

落爺英雄遲暮 提交于 2019-12-06 05:56:38
问题 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