Menu
  • HOME
  • TAGS

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

nhibernate,nhibernate-mapping,nhibernate-queryover

I do have an answer to this topic, solution which I do use. But it at the end means "do not use Fetch" - do it differently. So, please, take it at least as a suggestion. Check this Q & A: How to Eager Load Associations without duplication in NHibernate?...

how to map interface in nhibernate

c#,.net,nhibernate,nhibernate-mapping

Because ArticleBase implements IArticle and all your *Articles inherit from ArticleBase you shouldn't have any problem dependency injection wise with mapping your ArticleBase as the base class: public class ArticleBaseMap : ClassMapping<ArticleBase> { public ArticleBaseMap() { Property(x => x.Category, m => { m.NotNullable(true); }); // ... } } ...

Remove Proxy Classes Generated During Mapping in Fluent Nhibernate

nhibernate,fluent-nhibernate,lazy-loading,nhibernate-mapping,fluent-nhibernate-mapping

Just call: session.GetSessionImplementation().PersistenceContext.Unproxy(entity)...

map concrete types which implements interface using nhibernate mapping by code

c#,.net,nhibernate,nhibernate-mapping

This won't work in general. It could work only in case, that we've mapped the interface (acting as abstract class in fact) already, e.g.: 8.1.1. Table per class hierarchy, An example: <class name="IArticle" table="Articles"> ... <discriminator column="Discriminator" /> <subclass name="Article1" discriminator-value="Article1"> ... The Mapping-by-Code - inheritance: public class ArticleBaseMap :...

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

nhibernate,nunit,nhibernate-mapping,spring.net

To resolve the above issue, performed several steps, though I'm not sure specifically which one fixed it: Added reference to NHibernate.Validator, Version=1.3.1.4000 in my test project and NHibernate.Caches.SysCache, Version 3.1.0.4000 Added reference log4net, Version=1.2.10.0 to my test project to print out more diagnostic info Added references to System.Configuration, System.Web.ApplicationServices, and...

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

c#,nhibernate,db2,nhibernate-mapping,nhibernate-4

That error doesn't seems to be connected to problems with the foreign keys. It seems to be that the NHibernate can't find the XML files. The "common" problems are normally three: The XML files must be set (in their Properties) with the Build Action = Embedded Resource In the configuration...

NHibernate mapping returns null value

nhibernate,fluent-nhibernate,nhibernate-mapping

You may not like it, but the table structure described above, is not representing Entity relations you've created (so called one-to-one). In case, that one table contains column referencing the another table (FK), we have scenario: Each Order has exactly one (or null) Invoice. (many-to-one) Invoice can be referenced by...

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

c#,nhibernate,nhibernate-mapping

You, and Ayende in the link you gave, are creating queries in HQL using the CreateQuery method. This type of NH query must be written against NH entities, which means you must have a proper mapping, i.e. a Sales entity, and then write select count(*) from Sale as Ayende selects...

NHibernate: deleted object would be re-saved by cascade. Replace object and remove old one

c#,nhibernate,fluent-nhibernate,nhibernate-mapping

I tried explain what is happening in detail here NHibernate Deleted object would be re-saved by cascade Delete an item from many-to-many relationship I would say, that the point is here: the ProgramItem is referenced by some other collection. And that collection was also loaded into the session. The best...

Mapping the primary key of the table to the same table in Nhibernate

nhibernate,nhibernate-mapping,visual-studio-2013

Your xml mapping will be something like this: <?xml version="1.0" encoding="utf-8" ?> <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"> <class name="SchoolStructure" table="SchoolStructure"> <id name="ID"> <column name="ID"/> <generator class="native" /> </id> <many-to-one name="ParentStructure" column="ParentStructureEntityID" /> </class> </hibernate-mapping> And your class will be: public class SchoolStructure { public virtual int ID {get; private set;} public virtual...

Mapping to Date part of Sql DateTime

c#,sql-server,nhibernate,fluent-nhibernate,nhibernate-mapping

The way to go in case we need the skip the mapped relationship mapping (when CROSS JOIN with WHERE clause is needed) we can use HQL (only way, check e.g. here:) How to join Two tables of two non relashinship defined columns using Nhibernate QueryOver Nhibernate QueryOver JoinAlias UnRelated Entity...

NHibernate unidirectional one-to-many relationship not saving foreign key

c#,nhibernate,fluent-nhibernate,nhibernate-mapping,fluent-nhibernate-mapping

A Student belonging to the School is a many-to-one relationship. 5.1.11. many-to-one An ordinary association to another persistent class is declared using a many-to-one element. The relational model is a many-to-one association. (It's really just an object reference.) Its fluent version is .References() References / many-to-one References is for creating...

Fluent NHibernate HasManyToMany with a discriminator column specifying relationship type

c#,nhibernate,fluent-nhibernate,nhibernate-mapping,fluent-nhibernate-mapping

I would say, exactly as you pointed out in your comment: I actually do have the RelationTable mapped with 2 many-to-one references to Person (as PersonA and PersonB). Using one-to-many (HasMany), how then do you suggest I map Sons and Daughters (both List<Person>) in the Person class taking into account...

By code mapping of many-to-many with OrderBy

nhibernate,nhibernate-mapping,mapping-by-code

Replaced the many to many with one to many and introduced an entity that represents the relationship (followed advice from this article). This has the upside of allowing you to map the order-by column as well as other columns, and also solved the issue of restricting the number of items...

NHibernate mapping One-to-One with Foreign Key Association

nhibernate,nhibernate-mapping,fluent-nhibernate-mapping

As tried to explain here: NHibernate Many-to-one cascade, Many-to-one does not support cascade all-delete-orphan. And this kind of setting is able to delete entity, which is not referenced any more... Other words, making many-to-one reference null - will not trigger delete. So, mapping is ok, but functionality required above is...

NHibernate bycode mapping to a protected collection

nhibernate,mapping,nhibernate-mapping,protected,mapping-by-code

As we can see the overloaded method here: PropertyContainerCustomizer.cs public void Bag<TElement>(string notVisiblePropertyOrFieldName , Action<IBagPropertiesMapper<TEntity, TElement>> collectionMapping , Action<ICollectionElementRelation<TElement>> mapping) { ... } What we have to pass as the generic template is the TElement, the one used as ICollection<TElement>. And because the defintion is: // TElement is Items protected...

NHibernate map one-to-many relationship with intermediate table

c#,nhibernate,nhibernate-mapping,fluent-nhibernate-mapping

To map pairing table, without explicit Entity representing it, we have to use <many-to-many>. Also attribute table="..." must be present - to instruct NHibernate about that pairing table. (In case, that we assign Tags into Posts, we should not mark such mapping as inverse) <bag name="Tags" table="t_post_tag" lazy="true" cascade="none" inverse="true">...

Unable to create one-to-one relationship between entities

c#,nhibernate,orm,nhibernate-mapping

Found the correct way to do this: use a <many-to-one> mapping with an added unique constraint: <many-to-one name="Registration" class="UploadedDocument" column="RegistrationID" unique="true" /> For further reference: 5.1.12. one-to-one...

Bi-directional relationship in nhibernate 4.0

c#,nhibernate,fluent-nhibernate,nhibernate-mapping,fluent-nhibernate-mapping

I found the fix for the problem: The fix for the problem is to add Inverse to the mapping of the parent file. So, the mapping for Department will be: DepartmentMap : ClassMap<Department> { Table("...."); HasMany(x => x.Employees).KeyColumn("DeptId").Inverse().Not.KeyNullable(); } ...

NHibernate intermediate table mapping by code

nhibernate,nhibernate-mapping,mapping-by-code

The mapping as is is correct (at least the same was working for me). So, the question is from where is coming your exception?. Let's have a SQL SELECT query over your simplified table/entity Person: SELECT id FROM Person That would work. But if - in a not shown part...

NHibernate: could not initialize a collection:

asp.net-mvc,nhibernate,many-to-many,nhibernate-mapping

The issue should/could be in the <key> mapping: <bag name="Keywords" table="StatueKeyword" lazy="false"> <!-- <key> is representing column where current Statue ID should be searched while the below one seems to be the ID column of the pairing table so instead of this <key column="IdStatueKeyword"/> use this: --> <key column="IdStatue"/> <many-to-many...

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

c#,nhibernate,orm,nhibernate-mapping

Just few hints, summarizing the most suitable standards I found out when working with NHibernate. 1) If there is a bi-directional reference in persitence (DB column), express it in C# code bi-directional as well. Other words, if a child has reference to parent, parent should have reference to child. public...

NHibernate fluent mapping to an entity property

asp.net-mvc-4,nhibernate,fluent-nhibernate,nhibernate-mapping,fluent-nhibernate-mapping

You can use component mapping: Component(x => StoreAddress).ColumnPrefix("StoreAddress"); Component(x => OfficeAddress).ColumnPrefix("OfficeAddress"); Then create a component map for Address type: public class AddressMap : ComponentMap<Address> { public AddressMap() { //map properterties } } ...

Fluent Nhibernate One to One mapping with non primary key

c#,nhibernate,fluent-nhibernate,nhibernate-mapping,one-to-one

OK, with assignable ID we can do it like this. Firstly we should be sure, that the ID is assigned, so we can adjust the getter of the <id> ItemSaleCode like this: public class ItemSaleDetail { string _itemSaleCode; public virtual string ItemSaleCode { get { return _itemSaleCode ?? SaleParent.SaleCode ;...

NHibernate map one-to-many

c#,.net,nhibernate,nhibernate-mapping

Yup the problem was in line that suggested by AK_ (thank you for that). The only thing I changed was `<id name="Id" column="Id"> <generator class="native"/>` to `<id name="Id" column="AlbumId"> <generator class="native"/>` and <list name="Reservations" table="Reservation" cascade="all-delete-orphan"> <key column="Id"/> <index column="Position"/> <one-to-many class="FromCDToVinyl.DomainModel.Reservation, FromCDToVinyl.DomainModel"/> </list> to <list name="Reservations"...

Mapping recursive association using nhibernate

c#,.net,nhibernate,nhibernate-mapping

Not so sure what the real issues is, but my standard xml mapping for parent-child collection would look like this: <set name="ChildCategories" lazy="true" batch-size="25" inverse="true"> <key column="ParentId" /> <one-to-many class="Category"/> </set> While lazy is (as far as I remember) default, I prefer explicit statements I would say, that really essential...

How to map NHibernate variable table reference?

c#,nhibernate,nhibernate-mapping

Why don't you use Any? Class: public class ChildClass { public virtual ParentBase Parent { get; set; } // beware of proxies when casting... this may not work like this public Parent1Class Parent1 { get { return Parent as Parent1Class; } } public Parent2Class Parent2 { get { return Parent...

NHibernate SchemaExport does not create ntext columns

c#,nhibernate,orm,nhibernate-mapping,schemaexport

After some further reading, the ntext will be removed in future versions along with text and image https://msdn.microsoft.com/en-us/library/ms187993.aspx ntext , text, and image data types will be removed in a future version of Microsoft SQL Server. Avoid using these data types in new development work, and plan to modify applications...

using ModelMapper for NHibernate with mapping by code

c#,nhibernate,nhibernate-mapping,.net-assembly

You can add one class to the Addmappings from the assembly that it belongs to. My config is like this:- mapper.AddMappings(typeof(CmsMeta).Assembly.GetTypes()); Basically I have 50 or so mapping classes but only need to specify the assembly where one of them lives. NHibernate will auto scan that assembly to find the...

Nhibernate one to many relationship error

c#,mysql,nhibernate,nhibernate-mapping

The point here is that for both many-to-one and one-to-many we have to use the same column "CompanyId" The Company.hbm.xml <bag name="Clients" table="Client" lazy="false" cascade="all" inverse="true" > <!-- wrong column name, it must be parent reference in a child table --> <!-- <key column="ClientId"></key> --> <key column="CompanyId" /> <one-to-many class="ConsoleApplication1.Client,...

Delete an item from many-to-many relationship

nhibernate,fluent-nhibernate,many-to-many,nhibernate-mapping,cascading-deletes

The answer is (I am really sure) here: NHibernate Deleted object would be re-saved by cascade Let me re-phrase that for your case, what could happen: we remove an GrupoArquivo from ArquivoRetorno.GrupoModulos collection. During that transaction, unit of work, we also tuch and therefore load the GrupoModulo GrupoModulo gets initiated...

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

c#,nhibernate,many-to-many,nhibernate-mapping

Your mapping seems to be correct. Just not sure what is the session default FlushMode. To be sure, that it is not None, try to append into first using the session.Flush();. using (ISession session = NHibernateHelper.OpenSession()) { ... session.Flush(); } Reason why simple insert into User and Role is happening...

Not persister M:N with association class in NHibernate?

.net,nhibernate,nhibernate-mapping

If we want to create the pairing object as entity. We need mapping like this: <class name="Product" table="Products"> ... // as is <bag name="Categories" lazy="true" inverse="true" batch-size="25" cascade="all-delete-orphan"> <key column="id_product" /> <one-to-many class="ProductsOfCart" /> </bag> </class> <class name="Cart" table="Carts"> ... // as is <bag name="Products" lazy="true" inverse="true" batch-size="25" cascade="all-delete-orphan"> <key...

nhibernate mapping An association from the table Image refers to an unmapped class

c#,.net,nhibernate,nhibernate-mapping

Try this: public class ImageMap : ClassMapping<Image> { public ImageMap() { ManyToOne(x => x.Article, m => { m.NotNullable(true); m.Class(typeof(MyArticle)); }); } } ...

NHibernate how do you map a crossreference table to a bag?

nhibernate,orm,nhibernate-mapping

Well, your mapping seems to be correct, i.e. already returning the ProjectName. To be sure please, check that the object Project is mapped like this: <class name="Project" table="Project"> <id name="Id" column="ProjectID" generator class="native"/> <!-- above as the Id we have mapping for column ProjectId below the C# Name will contain...

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

fluent-nhibernate,nhibernate-mapping,fluent-nhibernate-mapping

I think you might need to specify the KeyColumn. I do something similar in one of my solutions and I would map the entities above as follows... mapping.HasMany(x => x.Bars) .Schema("Schema") .Table("FooBars") .Element("Bar") .KeyColumn("FooID") .ForeignKeyConstraintName("FK_FooBar_Foo") .Not.Inverse() .Cascade.All() .Fetch.Select(); This will give a table called Schema.FooBars. It will have a FooID...

@NotNull on default in JPA/Hibernate

java,hibernate,jpa,nhibernate-mapping

There are no such possibility. Not Nullable constraint is not what you always expect from a field, although it is used quite often. It is convenient when you can look at the attribute definition and tell everything out of it, without addressing to some high-level settings like "every field should...

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

asp.net,asp.net-mvc,nhibernate,asp.net-mvc-5,nhibernate-mapping

found the answer. it seems scheme key is changed in new nhibernate version changed <hibernate-configuration xmlns="urn:nhibernate-configuration-version-2.2"> to <hibernate-configuration xmlns="urn:nhibernate-configuration-2.2"> fixes the problem. Im sure because I retested back the first scheme. and boM! same error throw. so xmlns string is updated. how I found it. opened web.config>xml in menu>Schemes [added...

Convert XML mappings to Code Mapping for ISET of ManyToMany

nhibernate,nhibernate-mapping,hibernate-mapping,mapping-by-code

The where should belong to many-to-many as in the xml mapping Set(x => x.SystemRoles, m => { // set mapping }, col => col.ManyToMany(p => { // mapping of the many-to-many p.Column(x => x.Name("PrivilegeId")); p.Where("PrivilegeType = 'SystemRole'"); }) ); But not fully sure, if all features are already supported in...

How to properly display List in ComboBox, and make the value member point to the selected class object?

c#,winforms,combobox,nhibernate-mapping

Use this YourComboBox.DataSource = YourList<Category>; YourComboBox.DisplayMember = StringNameOfProperty; to fill your Combobox. To get the item behind the Propery-Value use: var item = (Category) YourComboBox.SelectedItem; ...

Mapping entity oneToMany with fluent nhibernate

c#,nhibernate,fluent-nhibernate,nhibernate-mapping,fluent-nhibernate-mapping

After all, with these SQL scripts (adjust for SQL Server in my case) CREATE TABLE CLIENTE ( CORE_ID int NOT NULL, CORE_NUMERO_MEDIDOR VARCHAR(50) ) CREATE TABLE MEDIDOR ( NUMERO_MEDIDOR VARCHAR(50), MARCA_MEDIDOR VARCHAR(50) ) With these entities (all properties are virtual) public class Cliente { public virtual int ClienteId { get;...

NHibernate JoinAlias on collection multiple times

nhibernate,nhibernate-mapping,nhibernate-queryover

To answer your question: ...Is it possible to avoid this problem or it's a limitation of HNibernate? Have to say NO. For more information see similar Q & A: Rename NHibernate criteria We are not querying the DB, not using SQL (which does allow to do a lot). Here we...

Mapping list of value objects in nhibernate

c#,.net,nhibernate,nhibernate-mapping,mapping-by-code

You should for sure use interface for your C# entity: public class House : Entity<Guid> { ... //public List<Door> Doors { get; set; } public virtual IList<Door> Doors { get; set; } And the mapping of the reference set is described here: Mapping-by-Code - Set and Bag by Adam Bar...

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

c#,asp.net,asp.net-mvc,nhibernate,nhibernate-mapping

The issue caused by:"a boolean field in your Project class may be marked as a varchar field in the database". I have a database column "ON_DIALYSIS" "VARCHAR2(1)", it was mapping as a bool in mapping class PatCon public virtual bool OnDialysis { get { return _onDialysis; } set { _onDialysis...

How to specify Schema for Lists while mapping Nhibernate by code

nhibernate,nhibernate-mapping

I have never used mapping by code, but i assume this is the solution: List(x => x.Students, l => { l.Where("deleted = 0"); l.Key(k => { k.Column("post_id"); k.NotNullable(true); }); l.Schema(Constants.DatabaseSchemaNames.Article); l.Table("tag_post"); }, x => { x.ManyToMany(m => m.Column("tag_id")); }); ...

NHibernate in hbm - Could not execute query

nhibernate,nhibernate-mapping

The HBM should be <sql-query name="SqlSrcMyStuff" callable="true" > <return-scalar column="RU_ID" type="System.Int32" /> <![CDATA[ select some_col AS RU_ID from some_table where somecol1 = :param1 and somecol2 = :param2 ]]> </sql-query> And a query var result = session.GetNamedQuery("SqlSrcMyStuff") .SetInt32("param1", 1) .SetInt32("param2", 1) .UniqueResult<int>(); The result here shoul be just an int, not...

entity -> interface relationship, how to map

c#,.net,hibernate,nhibernate,nhibernate-mapping

Why not create an interim abstract class public abstract class ImageArticle : ArticleBase { public virtual IList<Image> Images { get; protected set; } } So ComputerArticle : ImageArticle, etc and Image becomes: public class Image : Entity<Guid> { public virtual ImageArticle Article { get; set; } } And map: (I...