Questions tagged [nhibernate]
NHibernate is an open source object-relational mapper (ORM) for the .NET framework.
17,512
questions
-1
votes
1
answer
24
views
Select items from a group by where count is larger than 1
The following sample query:
select * from (
select m.name, count(m.id) c from mytable m
group by m.name) a
where a.c > 1
How do I build that using NHibernate QueryOver?
It is easy ...
0
votes
0
answers
20
views
NHibernate Cache (SLC) not updating collection cache when child entity deleted/created
I just started using NHibernate Cache (Second Level Cache) with Redis provider.
I have Student entity which has a bag of MailingAddress entity. And when I load a contact then I see a redis key Student....
-1
votes
0
answers
36
views
Add Join to existed IQueryable in NHibernate
How to Add Join to existed IQueryable in NHibernate?
this is existed query
var query =
from phoneCall in _session.Query<CRMKernelPhoneCall>()
where phoneCall.AnswerQuality != null &&...
-1
votes
0
answers
35
views
How do I do a SQL LIKE (contains) comparison using NHibernate literal SQL [duplicate]
I'm trying to perform the following query using NHibernate:
var sql = @"
SELECT DISTINCT i.Id
FROM Item i
WHERE i.Name LIKE '%:itemName%'
";
var query = session.CreateSQLQuery(...
0
votes
1
answer
43
views
NHibernate OrchardCMS and Long Id: object references an unsaved transient instance
I'm using OrchardCMS (1.10.x) as a Web Application. OrchardCMS use integer field as primary key on database (ContentItemRecord.Id). However, soon, the web application will need more than pass the max ...
0
votes
0
answers
19
views
NHIbernate generates invalid IDs in query
I am using in my C# project NHibernate v3.3.1.4 and FluentNHibernate v1.3.0.733 and my Database is MySQL.
I have a project which I use regularly, but lately I came across an error while using it.
...
0
votes
2
answers
33
views
How can i map a computed list property in nhibernate
My model contais the following:
public virtual DateTime LastSessionDate { get; set; }
public virtual List<double> Values { get; set; }
Values should be selected from other tables in a custom ...
2
votes
0
answers
38
views
Why does the StackExchangeRedis NHibernate Second Level Cache require a locking mechanism?
This provider has a locking mechanism, but other related providers (most notably NHibernate.Caches.CoreDistributedCache.Redis) have no such mechanism.
Is there a specific use case of this provider ...
0
votes
1
answer
42
views
NHibernate linq queries for updates don't respect the commit transaction
I'd like to update entities using linq queries provided by NHibernate. For example (from the official doc)
session.Query<Cat>()
.Where(c => c.BodyWeight > 20)
.UpdateBuilder()
....
0
votes
1
answer
35
views
Does Nhibernate uses distributed transaction in the background while mapping multiple entities to same table?
One good thing NHibernate has is ability to map multiples entities to same table without using inheritance too.
Example: for restaurant BoundedContext:
public class RestaurantCustomer
{
public int ...
0
votes
1
answer
34
views
nhibernate configuration not connecting to database
I encountered an issue:
A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance ...
0
votes
1
answer
49
views
nhibernate has invalid child element 'add'
I'm having issues running my application where it uses NHibernate. The runtime issue I'm getting is:
The element 'session-factory' in namespace
'urn:nhibernate-configuration-2.2' has invalid child ...
0
votes
1
answer
24
views
NHibernate subquery with not mapped column
I have problem with nHibernate.
Let's say there are 2 classes Client and Order
public class Client{
public int Id {get; set;}
public string Name {get; set;}
public List<Order> {get; set;}
}
...
0
votes
1
answer
32
views
Map a HasMany relationship without any key column whatsoever - Where() only
Conceptually I want to map a collection like this:
HasMany(x => x.Children).Where("some_column_name='foo'");
The default mode of HasMany() requires me to provide a KeyColumn which should ...
1
vote
0
answers
83
views
How to use dependency injection in Automapper 12.x ConstructUsing
We are using Automapper to map DTOs to entities.
To make sure that the created entity is always bound to the session (we use NHibernate), we have the following in the Automapper configuration:
var ...
0
votes
1
answer
55
views
NHibernate - map Oracle sequence to non-ID column
Assuming a table like this:
ID
FOO
BAR
NUMBER
VARCHAR2
NUMBER
And a class like this:
public class SomeClass
{
public virtual long Id {get;set;}
public virtual string Foo {get;set;}
...
0
votes
1
answer
75
views
Nhibernate gives System.NotImplementedException
I'm trying to do a left join between two table TaxInformation and ThirdParty knowing
The join works correctly but when I try to do a left join i got the exception with the message: 'System....
0
votes
0
answers
18
views
Nhibernate Dynamic Search With
I'm encountering an issue while working with NHibernate queries and joins. I have a scenario where I need to retrieve Holding entities based on specific conditions related to Insurance and Depot ...
0
votes
1
answer
19
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 ...
0
votes
1
answer
47
views
Using Orderby with conditional?
Hello I am trying to get a query to order by dates but if there is a due_date to use that if there isn't a due_date it needs to use sample_date. This is what i tried but it isnt correct.
is there a ...
0
votes
1
answer
30
views
(Fluent) NHibernate, Asynchrony, and Looping Issues
I'm having issues with the following:
for (var i = 0; i < domainEvents.Count; i++) {
_logger.Information("Publishing Event {@DomainEvent}", domainEvents[i]);
...
0
votes
1
answer
49
views
Problem getting list of related purchase order lines in sales order line
In my domain several purchase order lines can be assigned to one sales order line.
When the purchase order is created it is saved in the database with a new natural Primary Key (DocEntry, LineNum) and ...
1
vote
1
answer
80
views
Extract object encapsulated state through NHibernate
Context
I'm maintaining a WPF application which applies DDD principles. A strong focus has been made on encapsulating state (=making fields private as much as possible).
The state of the aggregates ...
-1
votes
1
answer
29
views
NHibernate never recognizes a joint request
Good time of day! To create a query, use Create query method:
string query = $@"INSERT INTO [{table_name}] ([p1], [p2]) VALUES (:p1_val, :p2_val)";
Session.CreateQuery(query)
....
0
votes
0
answers
50
views
How to convert `IQueryable` to `Expression<Func` to provide Projection list to NHibernate QueryOver?
Please refer to following code:
using(ISession session = SessionFactory.OpenSession())
{
//Case 1: using Query = works fine.
IList<MasterDto> listMaster = session.Query<MasterEntity&...
0
votes
0
answers
33
views
How to modify treeBuilder.Dot to generate LEFT JOIN instead of INNER JOIN in custom function generator for NHibernate?
Im trying to extend LINQ to NHibernate provider for my custom function. The problem that I found is that, whenever I try to access a FK from my entity, it generates a "INNER JOIN" statement, ...
0
votes
1
answer
57
views
NHibernate exception when creating SQL for DELETE with a condition from a JOIN
Tech Stack
SQL Server 2019, NHibernate 5.3.5, .NET Framework 4.8
Setup
Database
CREATE TABLE First (
Id UNIQUEIDENTIFIER PRIMARY KEY
);
CREATE TABLE Second (
Id UNIQUEIDENTIFIER PRIMARY KEY,
...
0
votes
0
answers
41
views
Mapping Entity to DTO doesn't work using NHibernate
I want to map certain properties from Entity to DTO, but it returns result count as 0
Entity:
public class CustomerForSendToBusinessCentralEntity : BaseEntity
{
public virtual Guid Id { get; set; }...
0
votes
0
answers
9
views
Why are Boolean and DateTime Literals Wrong in NHibernate SQL Logging?
I use log4net to log NHibernate.SQL at the Debug level.
I use the MsSql2012Dialect dialect against the latest Sql Server database.
The logged SQL is s bit different from the SQL that gets sent to the ...
0
votes
0
answers
34
views
NHibernate when using default-access="field.pascalcase-m-underscore" no ID value for proxy
I have the following classes:
public class Course
{
private string m_Name;
private long m_ID;
public virtual long ID
{
get => m_ID;
set
{
if (...
1
vote
1
answer
39
views
Problem mapping Fluent NHibernate One-To-Many
I am having issues mapping two classes to a database via Fluent NHibernate.
My classes are Asset and LogData.
Asset has a bunch of decimal configuration values, and a Log which is a LogData.
public ...
0
votes
1
answer
68
views
System.ArgumentException: The column 'EmployeeID' has already been added in this SQL builder (Parameter 'columnName')
I try to make a CRUD operations using NHibernate and Northwind database.
I'm totally a new with ORM tools and NHibernate.
To create config, mapping and entities files I used Devart.
When I try to add ...
0
votes
0
answers
59
views
NHibernate Queries with Common Table Expression
I have an SQL Server query of the kind:
WITH MostRecentToday AS (
SELECT *, ROW_NUMBER() OVER(PARTITION BY ItemGuid ORDER BY Version DESC) AS rn
FROM Items
WHERE Cast(Timestamp As date) = '...
0
votes
1
answer
56
views
NHibernate: Is it possible for IUserType to convert a value to null and have it output as IS NULL in the resulting query?
We are using NHibernate as our ORM. We have a table that one of the columns has a custom IUserType mapped onto it. The purpose of the IUserType is that depending on the type of connection we are ...
0
votes
1
answer
46
views
VB.NET NHIBERNATE trouble to do a query with where clause in
I've been looking all over the web to find the synxtax in VB to fix our problem.
We have been using our query like this when we need to search in a table a bunch of elements from a liste
Dim criteria ...
0
votes
1
answer
205
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 ...
0
votes
0
answers
25
views
How to create a NHibernate query with sub select, group by and three values
I have two entity classes/tables where I store events. Now I want to create a statistic which is grouped by start time, end time and interval.
The SQL looks like this:
select Value, Block, Count(*) as ...
1
vote
0
answers
35
views
EF Core: support for collections of value objects
Anyone knows it the latest version of EF Core supports value object collections? Ie, can the following NH mapping code be translated into EF:
HasMany(employee => employee.Contactos)
...
0
votes
0
answers
54
views
Unable to construct Instance of specified SQLExceptionConverter
I am new to Nhibernate and I am trying to fix a warning coming in our project but I am not able to understand from which method or class the exception is raising.
WARN - Unable to construct ...
1
vote
1
answer
37
views
Nhibernate System.IndexOutOfRangeException on not selected column
I am running into this Nhibernate related error that I have hard time debugging
I have the following class named OriginalDataSource
public class OriginalDataSource
{
private string ...
0
votes
0
answers
71
views
How can I configure my UnitOfWork/Repository to work when an `await`ed call changes threads?
How can I configure my UnitOfWork/Repository to work when an awaited call changes threads?
The code here is a fictional scenario which represents a common pattern we have in our production code.
When ...
0
votes
1
answer
203
views
Error while adding second level cache in Nhibernate configuration .Net Core 6
I have migrated my legacy Asp.Net project to a Asp.Net Core 6 solution.
I try to build the NHibernate session factory by adding a second level cache provider ('CoreDistributedCacheProvider') but I am ...
0
votes
1
answer
65
views
nhibernate transaction sometimes does not insert all records
After doing more research and listening to advice here I have been able to get closer to figuring out my issue. The NHibernate issue that I am having deals with a transaction and it has only been ...
0
votes
0
answers
97
views
NHibernate batch update/insert
I have a collection of entities (some of them are transient some already persisted).
I would like to perform batch update/insert.
Is there a way to do it without additional round-trips to DB (to check ...
0
votes
1
answer
107
views
nHIbernate query with conditional join
I'm trying to get an nHibernate query to work without success. Here is my data structure:
public class Permission {
public Guid Id {get; set;}
public string Name {get; set;}
}
public class ...
0
votes
2
answers
128
views
How to implement a Guid generator with insertBuilder on Nhibernate
I'd like to do a bulk insert with nhibernate using the insertBuilder.
But I want each row to have a unique Guid.
var mailIds = batch.Select(x => x.Id);
var guidGen = new GuidGenerator();
Dao....
1
vote
1
answer
40
views
NHibernate subquery to check atribute of referenced object
I need to filter a page of my Concept model, Concept references TelecoCompany, so I want to filter by the name of that TelecoCompany. I was having some errors while comparing, so I realized I need to ...
0
votes
0
answers
30
views
Fluent Nhibernate with oracle full text search Contains
Im using Nhibernate with linq query and need to use full text search with 'CONTAINS' like
CONTAINS(text, 'oracle', 1) > 0;
As i seen there is no solutions for generate this keyword with linq, there ...
0
votes
1
answer
43
views
Insert into table with "where" clause in the mapping
I'm trying to setup a mapping for a table with a composite key, but in which I'm only interested in the values with a fixed value in one of the key columns. Example:
first
second
value
100
1
42
100
...
0
votes
0
answers
20
views
nhibernate update when using Joined Subclasses strategy
I'm having the same problem reported here, but I cannot figure what was the solution:
Update issue
I have a Child class defined like this:
public class ChildMapping : JoinedSubclassMapping<...