Questions tagged [nhibernate-mapping-by-code]

Mapping-by-code is NHibernate's own API by which mappings can be configured by code. Introduced in NHibernate version 3.2.

nhibernate-mapping-by-code
Filter by
Sorted by
Tagged with
1 vote
0 answers
26 views

How to use an Id generator with JoinedSubclassMapping

With a ClassMapping, I could do this: public class FooMap: ClassMapping<Foo> { public FooMap() { Table("FOO"); Id(x => x.Id, x => { x....
Asky McAskface's user avatar
0 votes
1 answer
26 views

How to implement Cascading in NHibernate using ClassMap (mapping by code)?

I am having some trouble with what seems to be a relatively simple cascading operation, but which I simply cannot get to work. I have four (simplified) classes: class Class { uint? ID; //IDs are ...
GalaxyGuy's user avatar
0 votes
1 answer
309 views

How to map an entity as a class property of another entity using mapping by code (NHibernate)

I want my entity's text properties being saved in several languages. For this I just want to store a FK to the TextContent table (which basically contains only a key) and a separate Translation table ...
Alexandre A.'s user avatar
  • 1,679
0 votes
1 answer
146 views

Mappings classes into entities using Domain Driven Design with NHibernate as ORM

Hello I want to map class with encapsulated fields. Earlier i used EF Core to map my domain models on entities but this time i want to try something new and i choosed NHibernate as ORM. Below is my ...
siteCoreDeveloper2022's user avatar
0 votes
1 answer
135 views

One-to-one relationship in NHibernate using composite key

I'm trying to figure out the proper way to model a one-to-one (or one-to-zero) relationship in NHibernate, or indeed to learn categorically whether such a thing can be done. Currently I have two ...
Mark Embling's user avatar
  • 12.7k
1 vote
2 answers
1k views

NHibernate: How to insert C# [Guid] into MySQL [BINARY(16) DEFAULT (uuid_to_bin(uuid(),1))] column?

Environment: MySQL Server 8.0, .NET Core 3.1, MySql.Data 8.0.28, NHibernate 5.3.11 I have following table: CREATE TABLE `Master` ( `Row_Id` char(36) NOT NULL DEFAULT (uuid()), `Path` varchar(1000) ...
PNG's user avatar
  • 103
0 votes
1 answer
631 views

NHibernate: how to transform List<object> returned by a stored procedure to List<Entity> using IQuery?

Following is my stored procedure: CREATE PROCEDURE [dbo].[GetProducts_SP] AS BEGIN SELECT * FROM Products END And this is my code: // This code works IList<ProductsEntity> list = session....
Amit Joshi's user avatar
  • 15.9k
0 votes
1 answer
360 views

NHibernate Mapping-by-code One-To-One relationship: fetch by Join?

I have a table (UncommittedVideoFile) that has a strict one-to-one relationship with a different table (VideoOrImageAsset). When I load an UncommittedVideoFile, I want to load the VideoOrImageAsset ...
Andrew Shepherd's user avatar
0 votes
1 answer
247 views

Mapping a collection of Interface with NHibernate Mapping ByCode

With FluentNHibernate I mapped a collection of interface by specifying the concrete type in the mapping class. I'm trying to convert to Maping.ByCode. Entity classes: public class Parent Entity { ...
user995219's user avatar
0 votes
1 answer
48 views

NHibernate creates 2 fields in one-to-many relationship

I have the following entities, mapped by code: VarRecipeMapping.cs public VarRecipeMapping() { Table("var_recipe"); // ... Bag(x => x.Entries, m => { m.Cascade(...
kagmole's user avatar
  • 2,075
2 votes
1 answer
356 views

Why NHibernate create a temporary table when I call the Update method on Query?

I just want to update a column table based on a condition. Here my code : this.session.Query<EventEntity>() .Where(e => [...]) .Update(c => new { Enabled = true }); This call ...
Sébastien Ollivier's user avatar
2 votes
3 answers
791 views

C# NHibernate: How to do constructor injection into classmapping derived class?

I am new with NHibernate. I somehow not able to find answer for my issue. So let me ask here. How can I dependency inject something into a class like this: /* public abstract class ...
Erhan KALUÇ's user avatar
1 vote
1 answer
85 views

NHibernate 5.1 ManyToOne - delete orphan not working as expected

I have following entities: public class Person { public int Id {get;set;} public String Name {get;set;} public Passport Passport {get;set;} } public class Passport { public int Id {...
Maciej Pszczolinski's user avatar
0 votes
1 answer
65 views

How to make nhibernate not combine results from inherited objects?

I have a problem with nhibernate queries. The result i get back is a mix from two tables. How do i tell nhibernate not to combine the result from the different tables. This is my query: using (var ...
merger's user avatar
  • 722
0 votes
1 answer
2k views

nhibernate mapping by code identity not insert

I'm using nhibernate 5,1,1. Mapping by code when you add an entry, you send 2 requests select max (id) From Bred insert Into Bred (Id, Name, PetType) valuses ({value of max (id)}, text, 1) I need ...
Павел Богидаев's user avatar
1 vote
1 answer
655 views

I cannot turn off lazy loading in NHibernate

I'm aware that lazy-loading 'on' is the default setting in NHibernate. I switched lazy-loading off, using mapping-by-code, for the entity (Student) and the collection (Comments) contained within an ...
Len's user avatar
  • 63
1 vote
1 answer
806 views

Nhibernate mapping class component of interface type

Last week I received the assignment to look for an alternative to the NHibernate hbm mapping, and decided to give the NHibernate mapping-by-code a try (seen that the fluent NHibernate project hasn't ...
Century's user avatar
  • 285
-1 votes
1 answer
364 views

Insert into SQL Server database through NHibernate 4 with Session.Save using mapping-by-code

Currently experiencing issues with Session.Save() not inserting records and producing the following exception: null id in NHModels.Domain.Activity entry (don't flush the Session after an ...
RioC's user avatar
  • 101
0 votes
1 answer
143 views

NHibernate: Mapping protected members in component (composite-element) mapping

I'm building an application which uses NHibernate mapping by code, and I am unable to map protected properties when I use a component mapping (equivalent to hbm composite-element mapping) for a ...
RiddleMeThis's user avatar
1 vote
1 answer
252 views

NHibernate component mapping: Operand type clash: bigint is incompatible with time

I am writing an application which uses NHibernate mapping by code. When I have a TimeSpan mapped as a property of an entity, the TimeSpan is mapped correctly. However, if I put the TimeSpan within a ...
RiddleMeThis's user avatar
1 vote
1 answer
321 views

Formula property update

good day everyone i have some trouble with formula property, update and nhibernate suppose, i have next model: public class Model { public virtual Guid Id { get; set; } public virtual ...
anatoly.kryzhanosky's user avatar
2 votes
1 answer
83 views

NHibernate: c# action on cascade deletion

I've implemented one-to-many code mapping with cascade deletion. I have associated file with child entity. I want to delete file automatically on child cascade deletion. How can it be implemented?
Dem0n13's user avatar
  • 805
2 votes
2 answers
266 views

NHibernate Mapping-by-Code

How to add a additional field in the database schema(SQL) from NHibernate mapping exported that not exist on entity? I have: Property(x => x.Name, "Name"); Property(x => x.Description, "...
Cristian18's user avatar
0 votes
3 answers
2k views

Generate sequential Id for primary key column in NHibernate

How can I generate a Sequential guid for a primary key column in NHibernate. I know how to do that auto increment stuff. But I don't know how to create a sequential Guid for primary key. In the ...
Sony's user avatar
  • 7,186
0 votes
1 answer
638 views

NHibernate read timestamp column from SQL Server

I'm using NHibernate 4.0.0.4000 (with mapping by code) and SQL Server 2012. I have to access tables which (among others) contain a timestamp (otherwise also known as rowversion) column. Until now I ...
MilConDoin's user avatar
0 votes
1 answer
400 views

NHibernate hierarchyid SQL Server 2014

I am using NHibernate with mapping by code, connected an SQL Server. This server also contains file tables. The customer, for whom I develop, has an SQL Server 2012, which I also had for quite a ...
MilConDoin's user avatar
2 votes
1 answer
349 views

Mapping-By-Code ignores Column Name in BagPropertyMapper

I'm encountering a problem, and I think it's an NHibernate defect. My Database Schema, containing a simple Parent-Child mapping: TABLE Company ( ID BIGINT PRIMARY KEY ) TABLE ...
Andrew Shepherd's user avatar
5 votes
2 answers
1k views

NHibernate with mapping by code and a SQLite database: saving many-to-one parent-child entities, child gets a null foreign key

Variations of this question have been asked and answered many times and the answers have a lot of overlapping details. I have tried so many different things suggested by these answers, but none of ...
rory.ap's user avatar
  • 34.5k
0 votes
1 answer
780 views

Nhibernate mapping by code: many to many

I have problems understanding proper mapping (mapping by code) for updating my data. Here it is (simplified for the sake of clarity). [Persons] table is just a dictionary and is immutable. [Objects] ...
tester.one's user avatar
2 votes
2 answers
2k views

How to map Enum in NHibernate using Mapping by Code

I am getting following exception while accessing data form database using fluent NHibernate An exception of type 'NHibernate.HibernateException' occurred in NHibernate.dll but was not handled in ...
MANISH KUMAR CHOUDHARY's user avatar
1 vote
2 answers
277 views

Nhibernate Remove child collection without having property in the parent object

Suppose I have the following model public class Customer { public virtual Guid Id { get; set; } public virtual string Name { get; set; } } public class ActivityLog { public virtual Guid ...
petrov.alex's user avatar
  • 1,089
0 votes
1 answer
74 views

displaying parameters used in NHiberate classMapping class

I wrote a little console app that is supposed to write out properties for a given class. It works on "normal" classes, but it just shows a blank list when I try and pass in a NHibernate classMapping ...
SkyeBoniwell's user avatar
  • 6,773
1 vote
1 answer
1k views

NHibernate mapping by code ManyToMany

Problem I'm using NHibernate mapping by code to map relationships. In this case I map users to roles to privileges. Users and roles are in a n:m relationship, same for roles and privileges. The SQL ...
MilConDoin's user avatar
0 votes
1 answer
801 views

NHibernate - Joining by ID property, not object

I have the following tables : Customer(ID, Name) Transaction(ID, CustomerID, Date) The mapping objects for the tables are defined without objects, only primitive types : Customer(int ID, string ...
user779444's user avatar
  • 1,385
1 vote
1 answer
864 views

NHibernate mapping by code error message could not execute query

I am new to c# and NHibernate so please forgive me if this question is out of line. I am working on mapping a table in Nhibernate by code i keep getting this error: could not execute query I have ...
havmaage's user avatar
  • 593
0 votes
1 answer
297 views

NHibernate mapping by convention inheritance model mapping

I am trying to map this class structure: public abstract class Entity { public virtual Guid Id {get;set;} public virtual int Version {get;set;} } public class Parent: Entity { public ...
Luka's user avatar
  • 4,059
1 vote
1 answer
449 views

NhiberNate Map by code does not contain a definision for 'id'

I have played around with NHiberNate, I got it to work with xml definision, but I'm stuck in my Map by Code test. I have the following code : using System; using System.Collections.Generic; using ...
havmaage's user avatar
  • 593
1 vote
1 answer
2k views

Mapping in configuration file when using Nhibernate's mapping by code

I want to use mapping by code so I have a class Employee (namespace NHibernateTests.Classes) and a class EmployeeMappings (namespace NHibernateTests.Mappings) My whole nhibernate configuration is set ...
Serge Profafilecebook's user avatar
4 votes
1 answer
1k views

NHibernate mapping-by-code in .NET 4.6 throws "Cannot extend unmapped class"

I have project running for several months in same NH configuration that I opened today on a clean installation of Windows (VS 2015 RC is installed, also .NET 4.6 RC is installed, but project is ...
Lukas.Navratil's user avatar
1 vote
1 answer
271 views

NHibernate Formula based property + PostgreSQL interval

I'm using NHibernate with Mapping by Code and I have a property that is created by this formula. Property(x => x.IsInOverdue, mapper => mapper .Formula("(SELECT (state_ <> 3 ...
Lukas.Navratil's user avatar
0 votes
1 answer
383 views

How do I specify a property as required (NOT NULLABLE)?

I am trying my hand at NHibernate's built-in mapping by code. I've got it mostly working now. My problem is how do I configure which properties on my objects are required in the database within the ...
Origin's user avatar
  • 1,993
1 vote
1 answer
591 views

Filter nested models on property in last node with NHibernate

I am using NHibernate with mapping by code. I have three models: Solution, Installation and System. There are one-to-many relations between them. So that each Solution has a list of Installations, ...
Bagaboo's user avatar
  • 363
0 votes
1 answer
169 views

By code mapping of many-to-many with OrderBy

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. ...
Chet's user avatar
  • 199
1 vote
1 answer
77 views

Convert XML mappings to Code Mapping for ISET of ManyToMany

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 ...
Moiz's user avatar
  • 2,429
4 votes
1 answer
948 views

NHibernate Mapping By Code Cascade All-Delete-Orphans

How to set cascade to all-delete-orphans with mapping by code in NHibernate? [Flags] public enum Cascade { None = 0, Persist = 2, Refresh = 4, Merge = 8, Remove = 16, Detach = ...
samvdst's user avatar
  • 628
0 votes
1 answer
734 views

NHibernate mapping-by-code equivalent of <composite-index> for composite Dictionary keys

Is it possible to map a dictionary with a multi-column key using mapping-by-code? I have not yet found an equivalent to <composite-index> yet. Example entities: public class Warehouse { //...
chris's user avatar
  • 2,621
1 vote
1 answer
1k views

NHibernate intermediate table mapping by code

I know that there are similar questions to this topic on stackoverflow, but none of them could solve my problem. I'm stuck with it, for at least two days now. So here is my question: I have two ...
samvdst's user avatar
  • 628
0 votes
1 answer
2k views

Mapping list of value objects in nhibernate

I have model House which has list of doors (door represents value object) public class House : Entity<Guid> { public int Id { get; set; } public List<Door> Doors { get; set; } ... ...
user1765862's user avatar
  • 13.9k
1 vote
1 answer
853 views

How to map IList<string> with NHIbernate Mapping by code?

I have this class public class Users { ... public IList<string> Roles {get; set;} } I must map it to a DB schema that looks like this: CREATE TABLE Users ( AppId NVARCHAR(255) NOT ...
dstj's user avatar
  • 5,020
1 vote
1 answer
930 views

How to map One-To-Many in NHibernate using Set/List/Bag (by code)

Two simple classes: public class Order { public virtual IList<OrderLine> Lines { get; set; } } public class OrderLine { .... } I try to do mapping by code using: public class ...
ForestC's user avatar
  • 213