Questions tagged [nhibernate]

1

votes
0

answer
6

Views

Append WHERE clause to NHibernate's SqlString

I need to modify a NHibernate's SqlString before it's executed on the database. Specifically I need to append a WHERE clause to SELECT/UPDATE/DELETE statements. The WHERE clause may or may not be already present which means that I may have to either modify it or add another part. For that purpose I...
Leviathan
0

votes
0

answer
3

Views

How do I create this reference mapping in Fluent NHibernate and then read object?

If I need to map both the foreign key and the child object, i'm doing like this: References(x => x.Buyer).Column("BuyerId").Not.Insert().Not.Update(); Map(x => x.IdBuyer).Column("BuyerId"); Then i'll do: someVal.IdBuyer = 123; //In database exists Buyer with id = 123 Insert(someVal); At this moment...
Daniil Vat
0

votes
0

answer
3

Views

NHibernate QueryOver syntax with multiple tables

I have some problems with NHibernate QueryOver Syntax. I am not able to convert the following SQL to NHibernate QueryOver Statement: "select m.* " + "from authmodule m inner join authmoduleassignment ma on m.Id = ma.module_id " + "inner join authroleassignment ra on ma.role_id = ra.role_id " + "inn...
1

votes
2

answer
834

Views

Can I get the underlying conneciton and transaction objects from NHibernate?

Is it possible to get the DbConnection and DbTransaction objects from a NHibernate transaction? I need to combine some NHibernate calls with a third-part library inside the same transaction.
Jonathan Allen
1

votes
2

answer
765

Views

NHibernate: Is it possible to use stored proc when updating/deleting/inserting a class mapped on view?

Here is the preamble: I have a SQL View and mapped NHibernate C# class I only allowed to modify SQL View data through some stored procedures (Insert/Update/Delete) How to denote such logic in mapping file? Is it possible with only specific mapping or i need some supplementary code?
skaeff
1

votes
1

answer
729

Views

nhibernate. Bag is null after creation in same session

I have the object, which contain the list of objects. public class Product: IProduct { public virtual long Id { get; set; } public virtual string Name { get; set; } public virtual IList Functions { get; set; } } public class Function : IFunction { public virtual long Id { get; set; } p...
Kronos
1

votes
4

answer
5.1k

Views

Linq query nhibernate; not supported exception

I'm fairly new to nHibernate having come from an EF background and I'm struggling with the following query : _patientSearchResultModel = (from patient in _patientRepository.Query(patientSearch.BuildPatientSpecification()) join admission in _admissionRepository.Query(patientSearch.BuildAdmissionSpeci...
John Kattenhorn
0

votes
0

answer
3

Views

NHibernate concurrency locking crash with StaleObjectStateException instead of wait

I have a database column CaseSymbol with columns: id, Symbol, LastNo Over it runs a .NET MVC application in which multiple threads can get the symbol and increment LastNo. CaseSymbol symbol = this.context.CurrentSession.Get(id); symbol.LastNo++; then it crashes obviously on this.context.CurrentSes...
user2818842
1

votes
2

answer
5.7k

Views

Illegal attempt to associate a collection with two open sessions error when deleting via services

There are several posts related to this error but I'm running into something different. Very simple NHibernate scenario. Parent and child tables with one to many relationship. One parent can have multiple children. I need to delete a Parent record with child records so I put together very basic code...
InspiredBy
1

votes
2

answer
733

Views

MVC / Repository Pattern - Architecture

I have a project in which I am using NHibernate and ASP.Net MVC. The application is intended to allow users to track certain data and then produce views of statistics based upon the data entered. The structure of my application thus far looks something like this: NHibernate Layer: Contains Repositor...
Ant P
1

votes
2

answer
1.5k

Views

Convert SQL statement to NHibernate Query

I tried to ask this question yesterday, but I don't think my wording was very clear. Therefore, I've tried to reword the question below. We have an existing system which we are rewriting in MVC4, and we are using NHibernate 3.2 in our new system. In the old system, we build up a SQL statement simila...
Matt
1

votes
2

answer
6.4k

Views

Fluent nhibernate One-to-Many when Inverse is used Child table's Foreign key is null

I have a parent and child table and entites are created and mapped using one to many relation ship. On one to many side when i use Inverse() then the child table's foreign key value is inserted as null. public class TableA { public virtual long ID { get; set; } public virtual string Name { get; set...
Desmond
1

votes
1

answer
642

Views

NHibernate Transactions: Is the INSERT-UPDATE_DELETE order for a batch documented somewhere?

Preface: This question is a derivative of this answer, speaking specifically about NHibernate instead of Hibernate. As to Hibernate, javadoc to org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(EventSource) says: Execute all SQL and second-level cache updates, in a special orde...
Jim G.
1

votes
2

answer
905

Views

C# NHibernate QueryOver select multiple Properties

In my C# application I use NHibernate to get all rooms from my database table 'room'. using (ISession pSession = NHibernateHelper.OpenSession()) { IList roomList = pSession.QueryOver(). Where(x => x.FloorID == 3). .List(); } The table 'room' and also my Mapping class (Room.cs) contains lets say the...
Metalhead89
1

votes
1

answer
416

Views

NHibernate Profiler does not show query plan

My application uses NHibernate to connect to a MySQL database. The profiling works fine, but the links at the bottom ("See the x row(s) resulting from this statement" and "Query plan for this statement") do not work. When I click on the query plan statement, nothing happens. When I click on the "See...
Erik Schierboom
1

votes
3

answer
377

Views

NHibernate not persisting changes to my object

My ASP.NET MVC 4 project is using NHibernate (behind repositories) and Castle Windsor, using the AutoTx and NHibernate Facilities. I've followed the guide written by haf and my I can create and read objects. My PersistenceInstaller looks like this public class PersistenceInstaller : IWindsorInsta...
Rob Gray
1

votes
1

answer
109

Views

NHibernate instantiate collections on save

I am using NHibernate to persist my entities in the database. MY entities have some relationships between them resulting into some mapped collections. I my case I use the Iesi.ISet interface to map these collections. I was wondering if it's possible for nhibernate to check if the properties containi...
Alecu
1

votes
1

answer
160

Views

Why does StructureMap doesn't inject a property?

I have created a class which inherit from the Registry class. In this class I want to inject a property: ForConcreteType() .Configure .Setter(s => s.PersonSpecializationManager) .Is(t => t.GetInstance()); The property definition is as follows: /// /// Gets or sets the person specialization manager...
Martijn
1

votes
1

answer
720

Views

How to configure custom MySQL NHibernate Batcher?

NHibernate with MySQL Dialect does not support Batching out of the box. I have found custom MySQL Batcher for NHibernate on nuget. Also, following is the github link: https://github.com/Andorbal/NHibernate.MySQLBatcher But I do not know how to inject/set this into my hibernate.cfg.xml configuration....
CodingIsFun
1

votes
1

answer
317

Views

ServiceStack & NHibernate Integration creating two sessions?

I'm attempting to follow the blog post here: http://www.philliphaydon.com/2012/06/using-nhibernate-with-servicestack/ though I'm running into an issue with my code. Basically, I'm setting up the SessionFactory just like Phillip does and my service looks identical to Phillip's. The issue I'm running...
slashp
1

votes
1

answer
197

Views

Why is my NHibernate session available only sometimes in a windows service?

Here is the relevant config of NH using fluent StructureMap ISessionFactory sessionFactory = fluentConfig.BuildSessionFactory(); For().LifecycleIs(new HybridLifecycle()).Singleton().Use(configuration); For().LifecycleIs(new HybridLifecycle()).Singleton().Use(sessionFactory); For().LifecycleIs(new Th...
getit
1

votes
1

answer
1.4k

Views

FluentNHibernate - Overriding an IIdConvention with different Id generator and type yields exception

if i have a convention for mapping ids that is how i generally map that uses the hilo generatior on an int Id property with an int Id column: public class IdConvention : IIdConvention { private const int HiLoRange = short.MaxValue; public void Apply(IIdentityInstance instance) { instance.Column(inst...
Dave Rael
1

votes
2

answer
1.3k

Views

Why is ISession save not inserting?

It seems as if the insert is completed successfully , but the item is never actually inserted into the table. If I do a console dump immediately after the insert, it shows the item as being inserted, but when I do a show data on the table, it does not reflect this change. If I select "Show Table D...
Fabii
1

votes
1

answer
167

Views

Order by a function result in NHibernate?

I have a table in my database containing geographical locations. I want to write a function that finds the location that is closest to a point. I tried this in NHibernate: public Location GetClosestLocation(double latitude, double longitude) { var closest = Session.QueryOver() .OrderBy(location =>...
Oliver
1

votes
2

answer
748

Views

Moving from EF to Fluent NHibernate: Memory Leaks, Architecture

Good afternoon, I'm migrating a fairly large project over to Fluent NHibernate for use with mono. I've gotten most of the key functionality working well, however I'm having a memory issue. Currently, this code is in two of my controllers. This, does not seem even slightly optimal. But I'm unsure wh...
Chazt3n
1

votes
1

answer
778

Views

How to obtain an NHibernate session with a connection that has an active transaction

We are usin NHibernate as our DAL for the domain model. At the end of a bulk process I want to do some actions using the NHibernate DAL Something like: public void BulkUpdate() { var connection = new sqlConnection(“connectonstring”); var transaction = connection.BeginTransaction(); // Do Bul...
k.c.
1

votes
2

answer
1.6k

Views

Sql Lite Error while running Fixtures : Unable to find the requested .Net Framework Data Provider. It may not be installed

Can anybody please help to resolve this issue.. I tried saveral things after googling but yet no luck... This error occurs while running fixtures in my project. NHibernate.HibernateException : Could not create the driver from NHibernate.Driver.SQLite20Driver. System.Reflection.TargetInvocationExcept...
K D
1

votes
1

answer
882

Views

ICriteria adding Or Restrictions

I need to do a select as follows select * from produtos where Value = 10 or Value = 15 or Value= 20 .... being that I do not know how many values ​​will come, it will be in a loop on a list that the user will decide how many values ​​will be ... the problem is that if I do Criteria ICriteri...
Maicon
1

votes
2

answer
161

Views

nhibernate linq basics

I need to transform this query to nhibernate linq IEnumerable accounts = from a in dc.Accounts where (a.FirstName + " " + a.LastName).Contains(SearchText) || a.Email.Contains(SearchText) || a.Username.Contains(SearchText) select a; I tried with this but I"m stuck at the beginning so I need help. IE...
user1765862
1

votes
1

answer
2.8k

Views

NHibernate proxyfactory

I've installed NHibernate.3.3.2.4000 via Nuget into my MVC3 project, configured it without a proxyfactory.factory_class: NHibernate.Dialect.MsSql2008Dialect, NHibernate db 50 web true 1, false 0, yes 'Y', no 'N' but like this I'm getting the following error: The following types may not be used as pr...
Simon Martin
1

votes
2

answer
1k

Views

NHibernate Envers - how to audit revisions on a separate database?

I'm using Nhibernate Envers and I want Envers to save audit info on a separate database to keep things cleaner/more maintainable. I'm using this fluent configuration: var enversCfg = new NHibernate.Envers.Configuration.Fluent.FluentConfiguration() enversCfg.Audit(GetDomainEntities()) nhCfg.SetEnvers...
monster_in_parasol
1

votes
1

answer
131

Views

Use an expression tree in an method inside another expression tree

I have two classes: class Foo { string Name } class Bar { IList Foos; } And the following expression tree: var fooFilters = (Expression)(foo => foo.Name == "baz"); In NHibernate I can write: Session.Query().Where(bar => bar.Foos.Any(foo => foo.Name == "baz")); And it works. Although, I can't write:...
Andre
1

votes
1

answer
656

Views

NHIbernate “References” Property generating Select + 1 even though correctly OUTER JOINING

Ok, I am a little stumped on this NHibernate query. The confusion is around PasswordResetToken. Firstly, here is the mapping: public ContactMap() { Table("Contact"); Id(x => x.ContactId, "ContactId").Unique().GeneratedBy.Increment(); Map(x => x.EmailAddress); ... Map(x => x.JobTitle); References(x =...
Mark Gibaud
1

votes
1

answer
2.6k

Views

NHibernate query deadlock in case multiple connection

I have next transaction: Desc d = new Desc(); d.Descr = "new"; _sess.Transaction.Begin(); _sess.SaveOrUpdate(d); var desc = _sess.CreateCriteria(typeof(Desc)).List(); _sess.Transaction.Commit(); This transaction performs next query: BEGIN TRANSACTION INSERT SELECT COMMIT TRANSACTION When I perform...
Artemoniks
1

votes
1

answer
1.1k

Views

How to pass schema name in a variable to nHibernate's named query?

I have a named native sql query in one of my nhibernate mapping files as follows: And I am running this query as from my c# code as follows: var query = Repository.GetExecutingSession().GetNamedQuery("GetAllClients").SetString("MASTER_USER", "test$master").SetString("TRAN_USER", "test$tran"); var cl...
mridula
1

votes
3

answer
1.2k

Views

Problems with NHibernate optimistic concurrency in a web application scenario

I am using a Version field to control concurrency in a ASP.NET MVC 4 application. Mapping: ... other fields omitted for brevity... Entity: public class User { public virtual int Id { get; set; } public virtual int Version { get; set; } ... other fields omitted for brevity... I am using the following...
JustAMartin
1

votes
1

answer
281

Views

Nhibernate many-to-many add on both sides

I'm creating a many-to-many implementation with Nhibernate. Currently I have the below classes. In both classes I implemented the AddObjX(Objx obj) method to add the item to the collection. Obj1 { int id; Ilist obj2; } Obj2 { int id; Ilist obj1; } In the mappings I have HasManyToMany(x => x.Obj1) ....
Patrick
1

votes
1

answer
77

Views

Add event to cascade update

I'm using fluent NHinernate in my application with cascade all option. I have a complex model with a bunch of entities and relations in it. Everything is held by one entity (Contract) it has some collections of other entities. These entities have references to other entities / lists of entities. Whe...
Andrzej Gis
1

votes
2

answer
310

Views

NHibernate - why is this collection not initialized / eager fetched?

Considering this: var pfs = Session.QueryOver() .JoinAlias(pf => pf.Responses, () => responseAlias) .List(); followed by this Debug.Print(pfs.First().Responses.Count.ToString()); Why would that debug statment make NHibernate go back and requery the Response collection, surely it was initialized in t...
1

votes
1

answer
1.5k

Views

give parameters in sql expression in NHibernate

I want to use collation in a query in NHibernate and apparently the only way to do that (at least from what I found) is through adding an sql expression (Can I customize collation of query results in nHibernate?) So I have something like c.Add(Expression.Sql("Title COLLATE Divehi_90_BIN2 LIKE ?",...
netslaves

View additional questions