nhibernate-mapping

nhibernate many-to-many mapping - additional column in the mapping table?

社会主义新天地 提交于 2019-12-17 18:25:08
问题 I have following mapping definitions: <class name="Role" table="Role" optimistic-lock="version" > <id name="Id" type="Int32" unsaved-value="0" > <generator class="native" /> </id> <property name="RoleName" type="String(40)" not-null="true" /> <bag name="UsersInRole" generic="true" lazy="true" cascade="all" table="UserRoles" > <key column="RoleId" /> <many-to-many column="UserId" class="SystemUser, Domain"/> </bag> and <id name="Id" type="Int32" unsaved-value="0" > <generator class="native" />

nhibernate many-to-many mapping - additional column in the mapping table?

对着背影说爱祢 提交于 2019-12-17 18:21:07
问题 I have following mapping definitions: <class name="Role" table="Role" optimistic-lock="version" > <id name="Id" type="Int32" unsaved-value="0" > <generator class="native" /> </id> <property name="RoleName" type="String(40)" not-null="true" /> <bag name="UsersInRole" generic="true" lazy="true" cascade="all" table="UserRoles" > <key column="RoleId" /> <many-to-many column="UserId" class="SystemUser, Domain"/> </bag> and <id name="Id" type="Int32" unsaved-value="0" > <generator class="native" />

What is the correct way to define many-to-many relationships in NHibernate to allow deletes but avoiding duplicate records

孤街醉人 提交于 2019-12-17 17:54:11
问题 I've been fighting with an NHibernate set-up for a few days now and just can't figure out the correct way to set out my mapping so it works like I'd expect it to. There's a bit of code to go through before I get to the problems, so apologies in advance for the extra reading. The setup is pretty simple at the moment, with just these tables: Category CategoryId Name Item ItemId Name ItemCategory ItemId CategoryId An item can be in many categories and each category can have many items (simple

How to implement correctly IUserType?

一世执手 提交于 2019-12-17 11:27:30
问题 I need to create a custom type for NHibernate by writing a new mapper class that implements IUserType . While it is relatively straightforward to override most of the methods and properties, I get some difficulties to understand how to deal correctly with the following members: object Assemble(object cached, object owner); object DeepCopy(object value); object Disassemble(object value); object Replace(object original, object target, object owner); I do not understand what is exactly their

NHibernate and collection types

痴心易碎 提交于 2019-12-14 02:05:37
问题 I am trying to develop my very first project with Nhibernate 3.0. I've gone through loads of material (blogs, papers and samples) and I think I can understand the basics, pretty much. I think I've understood the meaning of different types of collection but than when I see the examples found on the Internet I think I haven't really understood. The documentation says that you should use a Set when you do not want duplicates and a List/Bag when you want to allow duplicates. Most of the samples I

What's the most productive way to do NHibernate mapping?

巧了我就是萌 提交于 2019-12-13 18:07:46
问题 I know annotations to do the hibernate mapping in Java and am looking now for a similar way to do the same in C# and NHibernate. I found out that there exists several approaches do the mapping in xml files NHibernate.Mapping.Attributes (NHMA) Fluent are there any more?? I tried NHMA and found out it had some blocking points for me... I don't want you to discuss, whats the best way to map models to NHibernate, but I was looking for a good comparison on the internet. Do you know such sites?

How to map an enum in a one-to-many relationship with NHibernate?

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-13 14:17:13
问题 I have the two separate tables. [users] [ roles ] +-----+ +-------+ | id | |user_id| +-----+ +-------+ | value | <- [Represented by the enum] +-------+ And the models for them. class User { int id; IList<Roles> Roles; } enum Roles { Worker, Manager, Director } As you see it is simple "one to many". User has many roles. How do I map those models in XML? 回答1: how is your mapping? did you try something like this: HasMany(x => x.Roles) .Cascade.All() .Table("UserRoles") .Element("RolesEnum"); 回答2

NHibernate mapping with forking inheritance model

此生再无相见时 提交于 2019-12-13 06:45:13
问题 I'm just starting out with NHibernate and am trying to do a mapping for my model. (this is a model-first, TDD approach, just creating the database now) My Class hierachy is something like : I'm trying to work out how to map this now using a mapping xml file? This is my table and what I want them to map to QuestionId - Int - [Question.Id] PmqccFormId - Int - [Question.PmqccForm.Id] InputtedAnswer - Int - [NormalQuestion.InputtedAnswer or JobVelocityQuestion.InputtedAnswer - they are both enums

NHibernate Many to many mapping with additional columns in the mapping table

梦想与她 提交于 2019-12-13 06:32:23
问题 There are two tables Person and Address. I have a mapping table PersonAddressMap which contains an additional column IsCurrent other than the two foreign keys (no explicit primary key column). I have created three mapping classes one each for Person, Address and PersonAddressMap. I need to access all the Addresses of a Person and also access all the Persons who have a particular address from Address, so I have a one-to-many to PersonAddressMap in both the Person and Address class. Now the

Fluent NHibernate join for property value

依然范特西╮ 提交于 2019-12-13 05:44:33
问题 I'm trying to join a table to retreive and set a property on a POCO. Here's the scenario... *NOTE - An application can belong to many user sessions. UserSession (Table) UserSessionId PK ApplicationId FK UserName Application (Table) ApplicationId PK Name UserSession (Poco) string UserName get; string ApplicationName get; I've tried a join like this: Join("Application", j => j.Inverse().KeyColumn("ApplicationId").Map(x => x.ApplicationName)); However, this uses the primary column of the