nhibernate-mapping

Minimal and correct way to map one-to-many with NHibernate

柔情痞子 提交于 2019-12-27 11:47:08
问题 I am new to NHibernate and C#, so please be gentle! I have the following two NHibernate entities: Employee { private long _id; private String _name; private String _empNumber; private IList<Address> _addresses; //Properties... } and Address { private long _id; private String _addrLine1; private String _addrLine2; private String _city; private String _country; private String _postalCode; //Properties } and they have a one-to-many relationship from Employee to Address (each employee can have

NHibernate - how to switch dynamically the generator for Id?

和自甴很熟 提交于 2019-12-25 10:06:27
问题 Right now I have all my mappings as hbm.xml. I want to switch dynamically the type of Id generator for certain entities from 'identity' to 'assigned' at runtime (application start). This is because I need to support importing data from previous system and keep existing ids. Is this possible? How? 回答1: The generator is part of the mappings, so you need to change the mappings before creating the session factory. This is easy to do with Fluent or ConfORM. It's possible to change XML mappings

Upgraded NHibernate and FNH DLLs - now getting “No persister” exceptions

房东的猫 提交于 2019-12-25 06:52:46
问题 I'm trying to upgrade my FNH Automapping project to the latest versions of NHibernate and Fluent NHibernate (NH 3.2 and FNH 1.3), but now I get a "no persister" exception on a derived class (though the base class still seems to be persisted properly). This derived class Automapped fine with the old dlls (FNH 1.0, NH 2.1.2) - I have not changed my mapping logic or these classes in any way. I upgraded my project by just copying the new dlls over the old ones, and deleting references to dlls

Nhibernate mapping - User and Friends

不羁岁月 提交于 2019-12-25 05:13:08
问题 I am trying a social network type scenario using Nhibernate as my ORM. I have a User table and a Friend table. User Table ---------- UserID FirstName LastName Email Friend Table ------------- UserID FriendUserID AddedDateTime This means the in the Friend Table it could have many to many records like A - B (A initiated a friend request to B, accepted) A - C (A initiated a friend request to C, accepted) B - C D - A (D initiated a friend request to A, accepted) B - E How can I have a Nhibernate

unique in .hbm.xml file not raising exception

≯℡__Kan透↙ 提交于 2019-12-25 04:56:19
问题 I am having the following in my .hbm.xml file <?xml version="1.0" encoding="utf-8" ?> <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" namespace="Core.Domain.Model" assembly="Core"> <class name="Category" table="Categories" dynamic-update="true"> <cache usage="read-write"/> <id name="Id" column="Id" type="Guid"> <generator class="guid"/> </id> <property name="Name" length="100"> <column name="Name" unique="true" index="IX_Category"/> </property> </class> </hibernate-mapping> I am having

NHibernate data retrieve problem

时光总嘲笑我的痴心妄想 提交于 2019-12-25 04:56:14
问题 These codes are working well when saving data. But it is unable to retrieve data from b_TeacherDetail -table. For example: TeacherRepository tRep = new TeacherRepository(); Teacher t = tRep.Get(12); Here, t.TeacherDetail is null . But I know that there is an entry in the b_TeacherDetail -table for teacher-id 12. Why? My tables are: Teacher {ID, Name, IsActive, DesignationID, DepartmentID} TeacherDetail {ID, TeacherID, Address, MobileNo} Teacher.cs public class Teacher { public virtual int ID

<map> with <index-many-to-many> won't save in NHibernate

不打扰是莪最后的温柔 提交于 2019-12-25 04:32:08
问题 I have the following mapping: <?xml version='1.0' encoding='utf-8'?> <hibernate-mapping assembly='Core' namespace='Core.Models' xmlns='urn:nhibernate-mapping-2.2'> <class name='Basket'> <id name='Id' column='id'> <generator class='native'/> </id> <property name="ExternalId" /> <map name="Items" table="BasketItems" cascade="save-update"> <key column="BasketId" /> <index-many-to-many class="Product" column="ProductId" /> <element column="Quantity" type="System.Int32" /> </map> </class> <

NHibernate: Two foreign keys in the same table against same column

落爺英雄遲暮 提交于 2019-12-25 02:57:49
问题 I am working on a consignment booking software. The consignment object has the following structure: public class Consignment { //Other properties public virtual Station FromStation{get;set;} public virtual Station ToStation{get;set;} } and here is the station object: public class Station { public virtual int StationId{get;set;} public virtual string StationName{get;set;} //I don't want this property but I have to keep it. public virtual Iesi.Collections.Generic.ISet<Consginment>

One-to-one Mapping issue with NHibernate/Fluent: Foreign Key not updateing

梦想与她 提交于 2019-12-25 02:44:51
问题 Summary: Parent and Child class. One to one relationship between the Parent and Child. Parent has a FK property which references the primary key of the Child. Code as follows: public class NHTestParent { public virtual Guid NHTestParentId { get; set; } public virtual Guid ChildId { get { return ChildRef.NHTestChildId; } set { } } public virtual string ParentName { get; set; } protected NHTestChild _childRef; public virtual NHTestChild ChildRef { get { if (_childRef == null) _childRef = new

How to bind a series of columns into a collection with NHibernate

血红的双手。 提交于 2019-12-25 01:52:39
问题 Please believe me when I say I understand this isn't the "right" way to do this. File this under large-complex-legacy-system questions. We have tables describing OCR'd data of documents. Each document type has its own table. Each table is generated based on the types of fields it expects. So have a schema which looks a bit like this: Table: DocumentTypes Field: Id Field: Prefix Table: DocumentFields Field: Id Field: DocId Field: Name And we would generate tables like: Table: Type1_Data