Questions tagged [nhibernate]

10536 questions
1

votes
2

answer
49

Views

How to prevent NHibernate SqlDateTime overflow when querying the database without using an IUserType?

Is it possible to prevent this exception when doing an NHibernate Linq query like the following: var dateFilter = DateTime.Parse('1500-01-01'); return _session.Query().Where(l => l.Date > dateFilter).ToList(); Result: SqlDateTime overflow. Must be between 1/1/1753 12:00:00 AM and 12/31/9999 11:59:59...
Martin D.
1

votes
2

answer
4.2k

Views

NHibernate output columns/projections of CreateQuery().list()

I have simple HQL query: var list = OpenSession() .CreateQuery('SELECT MAX(p.price) as max_price, COUNT(p.id) as count_all FROM Order o left join o.Products p') .List(); I would like to output 'max_price' and 'count_all' columns/projections as easy as possible. Something like: Console.WriteLine(...
knagode
1

votes
2

answer
544

Views

Adding column to many-to-many auto generated table

I have Class and Student objects. Both have collection of another as property. Which automatically creates many to many table. Is there a way to add column to this table which relates to the relationship without creating many-to-many table by myself ?
Haimon
0

votes
1

answer
25

Views

Connecting to Postgres using Fluent NHibernate throws Exception

Here is my Hibernate settings: FluentConfiguration configuration = Fluently.Configure() .Database(PostgreSQLConfiguration.Standard.ConnectionString(c => c .Host('localhost') .Port(5432) .Database('PEDAux') .Username('ped_admin') .Password('xxxxx')) .ShowSql) .Mappings(m => m.FluentMappings .AddFromA...
Edwin Bautista
1

votes
0

answer
55

Views

NHibernate - How to query entities with children using fetch=“join” and Transformers.DistinctRootEntity but selecting only some properties

I would like to select entities with its children using fetch='join' strategy in mapping - due to large amount of records in dataase. The query looks like this: IList questions = Session.CreateCriteria(typeof(QuestionForVisit)) .Add(Restrictions.Eq('IsTechnical', 0)) .CreateCriteria('ParentVisitMo...
Lukasz
1

votes
0

answer
66

Views

I am using NHibernate 4.0.0.GA to insert an XML value in Microsoft SQL Database but always getting errors for length of string.

I use an stored procedure for updating inserting data into database using Iquery. My code for inserting data is shown below .hbm.xml file: exec dbo.spInsertFiles :convertedDoc .cs file: IQuery query = this.Session.GetNamedQuery('InsertInvoiceDetails'); query.SetParameter('convertedDoc', convertedD...
Reshma Thomas
1

votes
1

answer
187

Views

Fluent NHibernate: How to perform INNER JOIN?

I was wondering if someone could help me. I want to perform SQL INNER JOIN operation by using NHibernate. First of all let me introduce you to the structure of my database. I have the following parameters into my C# method: int documentId, int userId, int folderId. My main goal is to get RoleDocume...
Joseph Katzman
1

votes
1

answer
72

Views

NHibernate map citext in postgresql

Does anybody know how to map string in NHibernate (via .hbm mapping) to Postgresql's 'citext' type? I tried setting sql-type='citext' like this: but that doesn't work - when querying database by this column case sensitive comparison is still made.
Alexander
1

votes
0

answer
57

Views

Expression type not supported using sum in Nhibernate

I am trying to use Sum in NHibernate and I am getting this error. Expression type 'NhSumExpression' is not supported by this SelectClauseVisitor. Below is my query. AmountShort = _session.Query().Where(conditions).Select(x => x.AmountShort ?? 0).Sum() I have also tried this AmountShort = _session.Q...
Testing123
1

votes
1

answer
72

Views

Nhibernate sort by datetime

I'm trying to sort by datetime2(7) using CreateCriteria: var projection = Projections.Property('date'); return session .CreateCriteria() .Add(Restrictions.Like('Type', type)) .SetProjection(projection) .AddOrder(Order.Desc('Date')) .List(); Yet returned order is wrong. Could anyone help me? I'd li...
1

votes
1

answer
121

Views

SharpArch.Domain.PreconditionException: 'An ISessionStorage has not been configured'

I tried to build ASP.NET Identity project with hibernate SharpArch.Domain.PreconditionException: 'An ISessionStorage has not been configured' https://github.com/Streamc/IdHiber I borrow code from https://github.com/nhibernate/NHibernate.AspNet.Identity/tree/master/source/NHibernate.AspNet.Web proje...
ifooi
1

votes
0

answer
33

Views

Enumeration error on results fetched using nhibernate CreateSQLQuery

In the following statement nhibernate throws an exception (Message = 'TipoSanguineo must implement NHibernate.UserTypes.IUserType'; InnerException = {'Unable to cast object of type 'Focus.Domain.Enums.TipoSanguineo' to type 'NHibernate.UserTypes.IUserType'.'}): IList sources = Repositorio.GetCurren...
Marco Antonio Quintal
1

votes
0

answer
520

Views

NHibernate 5 with Asp NET Core 2: Getting an exception when calling OpenSession

Exception: System.TypeLoadException: 'Could not load type 'System.Runtime.Remoting.Messaging.CallContext' from assembly 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.' Code: public void ConfigureServices(IServiceCollection services) { var mapper = new ModelMapper(); m...
jgonte
1

votes
0

answer
43

Views

Linq to composite-element parent property could not resolve property

Having such mapping file: With such entities public class Parent { public virtual int ParentId { get; set; } public virtual IList Children { get; set; } } public class Child { public virtual Parent ParentLink { get; set; } } I'm unable to execute following query: (from p in session.Query().SelectMa...
Sly
1

votes
0

answer
91

Views

Field not found in row: <name> while executing stored procedure with NHibernate via Npgsql provider

Stored procedure in postgresql: CREATE OR REPLACE FUNCTION create_user() RETURNS TABLE(id integer, name varchar(50), token varchar(50)) AS $$ declare newUserId int; BEGIN INSERT INTO public.user(name) values ('User'); newUserId = currval('user_id_seq'); RETURN QUERY SELECT u.id, u.name, u.token FRO...
Max
1

votes
1

answer
203

Views

How to fetch all entities - Nhibernate select n+1 with multi level deep

To explain my question let's assume I've got these two classes: public class Grandfather { private int Id; private int Version; private IList Childrens; } public class Father { private int Id; private int Version; private IList ChildrensAges; private IList ChildrenGradesOnMath; private IList Childr...
reuth vexler
1

votes
0

answer
80

Views

NHibernate query execution time take considerably long with transaction

In our web application, there is a bunch of operations that needs to be completed in a transaction that edits data in very crowded tables (between 5 - 40 millions of records). Currently it looks like this, using (var transaction = session.BeginTransaction() { try { //operations transaction.Commit();...
aykut
1

votes
0

answer
25

Views

Merge One-to-Many objects

I have 2 entity Block and Subblock where on sql FOREIGN KEY (id_block) REFERENCES block (id_block), @Entity @Table(name = 'block') public class Block { @Id @GeneratedValue(strategy = GenerationType.AUTO) @Column private long id_block; @Column private String name; @OneToMany(mappedBy = 'block',casca...
Taras Danylchenko
1

votes
0

answer
53

Views

Nhibernate - No row with the given identifier exists when related records are not found

I'm have two tables in my database (Products and StockItems), in which are related. In addition, i have a view model that represents the product entity, with a list of stock items. To parse one class to another, i'm using AutoMapper. I'm receiving an exception when i try to parse my product to my pr...
Eduardo Ghidini
1

votes
0

answer
57

Views

NHibernate JoinAlias avoid select of nested items

I have a parent children relation, and I need to filter parent and children i some way, here a snippet example: Child childAlias = null; session.QueryOver() .JoinAlias(i => i.Children, () => childAlias) .Where(() => childAlias.Name == 'Child01') .And(u => u.Id == 'a4ccba801f1844b4921e17edb9ffa13f')...
Luca Mazzanti
1

votes
0

answer
61

Views

Nested abstract base classes and table-per-concrete-class in fluent nhibernate

I am having a problem replacing a legacy ORM with fluent nhibernate. I am trying to figure out how to map nested abstract classes with table per concrete class, while using Automap. Compared to the examples I have found, I have two abstract classes in my hierarchy. public abstract class AbstractBase...
fabsulous
1

votes
0

answer
126

Views

NHibernate many-to-one CRUD operations

I'm looking for a an example of CRUD operations for many-to-one NHibernate schema. I've found only basic examples and they didn't help me. I try to insert a new object in the DB and get NHibernate.Exceptions.GenericADOException Code for insert operation: public bool CreateBook(Book book) { try { usi...
firienn
1

votes
0

answer
55

Views

Fluent Nhibernate Mapping Issue/Query Issue

Thanks for the help everyone. I am using Fluent Nhibernate and having some mapping issues. So basically I have two tables....Person and Patient. Person has a PK called Id and Patient has a PK called PersonID which is also an FK to Person.Id. Table - Person PK - Id Table - Patient PK - PersonId (F...
Zach Davis
1

votes
0

answer
38

Views

How to keep updating DataGridView when database is updated

I'm working on a program that uses NHibernate to communicate with a SQL Server, and displays a table in a DataGridView. This is how I initialize my DataSource: private void UpdateDatabaseBindings() { if (InvokeRequired) { InvokeUI(UpdateDatabaseBindings); return; } using (var session = NHibernateH...
Ilan321
1

votes
1

answer
75

Views

Nhibernate sequence with c#.net

I have a conversion project (from oracle to sql server) and using NHibernate to handle database operations. Saving is working when we Save entity by using oracle . here for a column has sequence But same if we do in SQL server it is not working as getting 'null Identifier' . want to remove scope_i...
user455915
1

votes
0

answer
52

Views

Returning ROW_NUMBER() from Nhibernate QueryOver

I've been feverishly trying to figure out how to return the ROW_NUMBER() (not the row count) from a NHibernate QueryOver. This has now become equal parts a learning exercise, so i understand that there are easy alternatives like returning the whole set and iterating through it. But lets stick with...
Juls
1

votes
0

answer
34

Views

NHibernate namedquery vs sqlquery

There are several articles that suggest to use NHibernate named queries instead of native SQL queries. I mean Session.GetNamedQuery() vs Session CreateSQLQuery(). It is said that named queries are parsed in application startup and put in cache for using later, sql-queries are parsed every time they...
DNQ
1

votes
0

answer
80

Views

NHibernate many to one results in Operation is not supported

Hi I'm making a web app on .net core 2 using NHibernate. When I try to add many to one mapping in .xml I get this exception: fail: Microsoft.AspNetCore.Server.Kestrel[13] Connection id '0HLEFGR5COP4F', Request id '0HLEFGR5COP4F:00000002': An unhandled exception was thrown by the application. System....
Andrej Paučo
1

votes
1

answer
102

Views

NHibernate .SelectList() with List<string> in C#

I have a database request which looks as follows: var userHasProfessions = xy.GetUserProfessions(); var users = sessionService.GetDefaultSession() .Query() .Where(a => userProfessions.Contains(a.Profession.Id)) .ToList(); It gets all users that the requesting user is allowed to see, depending on his...
1

votes
1

answer
68

Views

NHibernate is unable to resolve classes in a dynamically loaded assembly loaded from a subdirectory

//Formatting is not properly done. Using nopcommerce plugins written in nhibernate and .net core, each plugins contains its own entities directory, but when NHibernate configuration fails var cfg = new Configuration(); cfg.Configure(CommonHelper.MapPath('~/App_Data/db/defauls.config')); // error he...
Joyce K
1

votes
0

answer
11

Views

How can I register two database connections with nhibernate/lightcore?

I have to set up to the existing database(Ms Sql) another one(PostgreSql) with Fluent Nhibernate for my C# Mvc Applicaton. Someone know how can I register the postgreSql database in the LightCoreConfiguration (global.asax)? Global.asax protected void Application_Start() { MvcHandler.DisableMvcRespon...
Alex
1

votes
0

answer
58

Views

Fluent NHibernate disable cache globally

I am using fluent nhibernate. I have problems with the caching so i would like to disable it. How can i disable the cache globally for all queries, without adding session.clear or REFRESH before every query?
Ravid
1

votes
1

answer
147

Views

C# Fluent NHibernate Overview Mapping

I have three classes: public class BaseEntity { public int Id { get; set; } } public class DocumentOverview : BaseEntity { public string Name { get; set; } } public class Document : DocumentOverview { public byte[] Data{ get; set; } } In my application there is a tree and I want to load document nam...
horotab
1

votes
1

answer
39

Views

NHibernate - deleting row is postponed to Commit(), but adding row not.

My problem is that the NHibernate postpones operation of deleting rows, whereas other operations are not postponed, and it causes exceptions. In my database I have User table with unique field: Login. I am using NHibernate 5.1.3, .NET version 4.6.1, C#. Below I paste the fragment of my code that...
Konrad
1

votes
0

answer
296

Views

Fluent NHibernate with ASP.NET core

I am building a web api with Asp.net core and FluentNHibernate however I am getting the following exception: An invalid or incomplete configuration was used while creating a SessionFactory. The inner exception is: Could not load type System.Diagnostics.PerformanceCounter from assembly. I research...
Andra Avram
1

votes
1

answer
62

Views

NHibernate Linq Expression dynamic projection

How can i dynamically change the selected columns in the generated sql query when using a linq expression? Its a new session for each time the query is executed. Even when I set the MapExp as null after first creation an then changing the bool value to false, it still generates the column in the sql...
marjohansson73
1

votes
2

answer
121

Views

NHibernate hasOne lazy load

I have a parent-child relation, with just one child on Sql Server. The child contains fat blob data I won't load. The child is optional and it must depend on the lifecycle of the parent. So the foreign key on the child, point to the parent and is unique. I can use the official example on Hibernate r...
Luca Mazzanti
1

votes
1

answer
38

Views

NHibernate throws an exception 'Data Source cannot be empty'?

I'm a newbie to NHibernate and trying to get my first app working with NHibernate + SQLite - In memory DB. so far, I've done the following, hibernate.cfg.xml NHibernate.Connection.DriverConnectionProvider NHibernate.Driver.SQLite20Driver 'Data Source=:memory:;Version=3;New=True;' NHibernate.Dialect....
SanVEE
1

votes
1

answer
167

Views

NHibernate - Error dehydrating property value - updating entity

I'm having problem when saving an entity with association. Below is my code which gives the error Fluent Class inherited from Fluent Migration public override void Up() //Update your changes to the database { Create.Table('assinatura') .WithColumn('id').AsInt32().Identity().PrimaryKey() .WithColumn...
Paulo Balbino
1

votes
1

answer
279

Views

Best practices with interface projections for JPA Repository in Spring?

I was wondering if anyone can give feedback on a pattern that I am currently playing around with? It involves having an entity implementing a DTO interface that is also used (as a projection) in a JpaRepository interface – for the same entity – to return query results with specific columns. The...
Andy Tang

View additional questions