FAQ Database Discussion Community


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

c#,nhibernate,orm,nhibernate-mapping
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...

Empty association table when trying to save many-to-many relationships between entities

c#,nhibernate,many-to-many,nhibernate-mapping
I have User entities (User mapping file) and Role entities (Role mapping file). I create some Users and Roles, assign roles to users and users to roles, save the whole lot, retrieve a User and test some assumptions (which fail). Here's my test code: [Test] public void TestUsersAndRolesWithoutWrappers() { //Ensure...

NHibernate fluent mapping to an entity property

asp.net-mvc-4,nhibernate,fluent-nhibernate,nhibernate-mapping,fluent-nhibernate-mapping
I have a table called "Customers" and in this table there are store and office address. In the code there is a Customer class with two properties that are of type Address (one for StoreAddress and OfficeAddress). public class Customer { public virtual int Id { get; set;} public virtual...

Not persister M:N with association class in NHibernate?

.net,nhibernate,nhibernate-mapping
I want to map a M:N asociation betwen Products and Cart with asociation class ProductsOfCart betwen them. However data is not persister but I dont know why can you help me? Here is a code from CartControler Create(); Product productD = new ProductDao().GetById(product); ProductsOfCart productsOfCart = new ProductsOfCart(); User user...

Nhibernate one to many relationship error

c#,mysql,nhibernate,nhibernate-mapping
I am encountering foreign key error while saving child record for parent-child relationship in nhibernate. I am using Mysql as the database. Value of foreign key column inserted is "0" Table CREATE TABLE Company( Id INT NOT NULL AUTO_INCREMENT, Name Varchar(100) NOT NULL, PRIMARY KEY (Id) ); CREATE TABLE Client(...

NHibernate mapping returns null value

nhibernate,fluent-nhibernate,nhibernate-mapping
I have a problem with mapping in NHibernate. The Order table has the Invoice_Id column which is the nullable FK to the Invoice table. The problem is, when I load an Invoice which Id exists in the Order table, I see that ConnectedOrder property is null, why? public class Invoice...

SetUp : Spring.Objects.Factory.ObjectDefinitionStoreException : Error registering object with name 'NHibernateSessionFactory' defined in 'assembly

nhibernate,nunit,nhibernate-mapping,spring.net
When I run a unit test, this is the error I'm getting: SetUp : Spring.Objects.Factory.ObjectDefinitionStoreException : Error registering object with name 'NHibernateSessionFactory' defined in 'assembly [Eiq.Middleware.Data.DomainRepository, Version=1.0.0.0, Culture=neutral, PublicKeyToken=5c61376b85e43767], resource [Eiq.Middleware.Data.DomainRepository.Persistence.xml] line 15' : Could not resolve placeholder 'TDM.providerName'. at...

NHibernate Fetch/FetchMany duplication in resultset, how to fix with ToFuture()

nhibernate,nhibernate-mapping,nhibernate-queryover
I'm relatively new to using NHibernate and I'm running into a shortcoming I can't seem to work myself around. I have an object tree that I wish to retrieve from the database in a single roundtrip but end up with a cartesian product. The objects I'm trying to retrieve are...

How to specify Schema for Lists while mapping Nhibernate by code

nhibernate,nhibernate-mapping
I want my "tag_post" table to be created in "article" schema but it's created in "public" schema. List(x => x.Tags, l => { l.Where("deleted = 0"); l.Key(k => { k.Column("post_id"); k.NotNullable(true); }); Schema(Constants.DatabaseSchemaNames.Article); l.Table("tag_post"); }, x => { x.ManyToMany(m => m.Column("tag_id")); }); ...

Convert XML mappings to Code Mapping for ISET of ManyToMany

nhibernate,nhibernate-mapping,hibernate-mapping,mapping-by-code
I am presently working on one of the project, where I need to convert the xml mappings to code mappings. I have a ISET collection with Many to Many along with where clause. I had done the code mappings but where to put the where clause in code mappings ?...

NHibernate asks hibernate.cfg.xml even if web.config configured

asp.net,asp.net-mvc,nhibernate,asp.net-mvc-5,nhibernate-mapping
this is ASP.NET MVC 5 Sample App. trying to learn MVC's module NHibernate. if I understand right. hibernate.cfg.xml file is not neccessary if settings coded in web.config as a configsection. is xmlns version is wrong ? or do you see something misspelled ? so why NHibernate asks hibernate.cfg.xml even if...

Mapping to Date part of Sql DateTime

c#,sql-server,nhibernate,fluent-nhibernate,nhibernate-mapping
I have a requirement to be able to fetch data related to a particular Date as opposed to DateTime, for a particular colmumn. Is it at all possible to Map the related objects according to an extracted date part of a date time? Where no explicit foreign key relationship exists...

NHibernate map one-to-many

c#,.net,nhibernate,nhibernate-mapping
I have question about doing one-to-one map in NHIbernate. I have two classes, Album class: public class Album { private int id; private string name; private DateTime releaseDate; private int numberOfTracks; private int totalLength; private int mediaNumber; private Artist artist; private Label label; private Media media; private int reservationId =...

Create relation one-to-many without Foreign Key in nhibernate4

c#,nhibernate,db2,nhibernate-mapping,nhibernate-4
i'm new to NHibernate 4 and i try to create a one-to-many relation between two table in DB2, the tables don't have a foreign key and i can't edit the tables. When debug the application i catch error in .saveorupdate method. The tables contains: TLDMAIN->summary of article TLDDETAIL->detail of article...

Encountering an “undefined alias or unknown mapping” exception when using NHibernate's Multi Query feature

c#,nhibernate,nhibernate-mapping
I am trying to implement a NHibernate's Multi Query feature for a typical Paging and Counting functionality using NHibernate version v2.0.50727. I've been following the example given here by Ayende Rahien and my code is a lot similar to it. However, every time it hits the call to return the...

How to map a string collection from another table in Fluent NHibernate?

fluent-nhibernate,nhibernate-mapping,fluent-nhibernate-mapping
I have an entity: public class Foo { public virtual int Id; public virtual IEnumberable<string> Bars; } And its mapping: public class FooMapping : ClassMap<Foo> { public FooMapping() { Table("foo_table_in_database"); Id(x => x.Id, "Id"); HasMany(x => x.Bars) .AsList() .Table("bars_table_in_db") .Element("BarId", m => { m.Type<string>(); }); } } And an exception...

Nhibernate exception: base {NHibernate.HibernateException} = {“illegal access to loading collection”}

c#,asp.net,asp.net-mvc,nhibernate,nhibernate-mapping
I am working on an NHibernate exception :"base {NHibernate.HibernateException} = {"illegal access to loading collection"}" Table PatRef is Parent table. Table PatCon is Sub table. When I retrieve data from PatRef to PatCons at debuging mode, the error message screen shot is below. The Nhibernate data mapping screenshots are below....

By code mapping of many-to-many with OrderBy

nhibernate,nhibernate-mapping,mapping-by-code
I'm using by code mappings and trying to map a manytomany. This works fine but I need OrderBy for the child collection items. I noticed this has been omitted (it does exist in the HBM mappings). e.g. public class Mapping : EntityMapper<Category> { public Mapping() { Set(x => x.Items, m...

Unable to create one-to-one relationship between entities

c#,nhibernate,orm,nhibernate-mapping
Update 1: Added a link to the code for the entity classes. I have a Vehicle entity (to hold information about a vehicle) and an UploadedDocument entity (represents any uploaded document, in this case (say) the registration papers) being stored in the DB in separate tables (other entities may also...

Bi-directional relationship in nhibernate 4.0

c#,nhibernate,fluent-nhibernate,nhibernate-mapping,fluent-nhibernate-mapping
I have a code that was working perfectly on NHibernate 3.1, but when it is not working on NHibernate 4.0 So, this is the class relations public class Employee : BaseEntity { ... public Department Dept { get; set; } } public class Department : BaseEntity { ... public IList<Employee>...

NHibernate map one-to-many relationship with intermediate table

c#,nhibernate,nhibernate-mapping,fluent-nhibernate-mapping
How to define mapping without intermediate class PostTag creation? I have three tables t_post(id...) t_tag(id, name) t_post_tag(id,post_id, tag_id) I want to have a collection with Tags in Post type classes: class Post { public virtual IEnumerable<Tag> Tags{ get; set; } } public class Tag { } mappings: <?xml version="1.0" encoding="utf-8"?>...