nhibernate

Translate query to NHibernate

I am trying to learn NHibernate, and am having difficulty translating a SQL query into one using the criteria API. The data model has tables: Part (Id, Name, ...), Order (Id, PartId, Qty), Shipment (Id, PartId, Qty) For all the parts I want to find the total quantity ordered and the total quantity shipped. In SQL I have: select shipm...

Count number of queries executed by NHibernate in a unit test

In some unit/integration tests of the code we wish to check that correct usage of the second level cache is being employed by our code. Based on the code presented by Ayende here: http://ayende.com/Blog/archive/2006/09/07/MeasuringNHibernatesQueriesPerPage.aspx I wrote a simple class for doing just that: public class QueryCounter : I...

Call Stored Procedure in Nhibernate - exception - No persister for

I am getting exception when calling Stored Procedure using Nhibernate and here is the exception No persister for: ReleaseDAL.ProgressBars, ReleaseDAL, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null here is class file public class ProgressBars { public ProgressBars() { } private Int32 _Tot; private Int32 _subto...

Problem with SQLite related nUnit-tests after upgrade to VS2010 and Re#5

After converting to Visual Studio 2010 with ReSharper5 some of my unit tests started failing. More specifically this applies to all unit tests that use NHibernate with SQLite. The problem seem to be related to SQLite somehow. The unit tests that does not involve NHibernate and SQLite are still running fine. The exception is as follows:...

NHibernate Unique Constraint on Name and Parent Object fails because NH inserts Null

Hi, I have an object as follows Public Class Bin Public Property Id As Integer Public Property Name As String Public Property Store As Store End Class Public Class Store Public Property Id As Integer Public Property Bins As IEnumerable(Of Bin) End Class I have a unique constraint in the database on Bin.Name and ...

HQL query problem

Hi all, I'm using this hql query for my filters. Query perfectly working except width (string) part. Here is the query, public IList<ColorGroup> GetDistinctColorGroups(int typeID, int finishID, string width) { string queryStr = "Select distinct c from ColorGroup c inner join c.Products p " + ...

NDbUnit MySQL Assembly Version Conflict

I am trying to use NHiberanate with NDbUnit but I cannot as NDbUnit tried to load MySql.Data version 1.0.10.1 and NHibernate tries to load version 6.2.2.0 and I can only reference one of them. Here is the error I get when i try to run NDbUnit Set Up System.IO.FileLoadException: Could not load file or assembly 'MySql.Data, Version=1.0.1...

Restricting deletion with NHibernate

I'm using NHibernate (fluent) to access an old third-party database with a bunch of tables, that are not related in any explicit way. That is a child tables does have parentID columns which contains the primary key of the parent table, but there are no foreign key relations ensuring these relations. Ideally I would like to add some forei...

NHibernate: Can I access a generated primary key after saving a model?

Howdy, So I've got a simple table with an ID field that's incrementally generated on INSERT. I've set the mapping up in NHibernate to reflect this: <id name="ID"> <generator class="identity" /> </id> And it all works fine. Trouble is, I need to get the generated ID after I've saved a new model to use elsewhere: var model = new M...

NHibernate MySQL Password Function

I am trying to create a custom application that allows for adding and removing and changing passwords of users. How would I create the hash that MySQL uses to stored password in? I know MySQL has a Password() function but I can't figure out how to use this function in NHibernate. Anyone know how to do this? ...

NHibernate Query across multiple tables

I am using NHibernate, and am trying to figure out how to write a query, that searchs all the names of my entities, and lists the results. As a simple example, I have the following objects; public class Cat { public string name {get; set;} } public class Dog { public string name {get; set;} } public class Owner { public string...

How to deal with database access in long-running 2-tier application?

I am currently working on server application that has to deal with reasonable amount of clients over TCP in LAN. Tasks that server has to accomplish vary from trivial to mildly-complex, and most of them include some form of database interaction. I'd like to make database access asynchronous, since not all queries are equally complex. Th...

NHibernate Queries with Values Produced by Business Logic

I have an NH query which returns a Product with a BasePrice. Depending on various other factors, such as Manufacturer price markup, I use a PricingService on the C# side of things to produce a "final" price. The issue is that I now need to query against this final value - i.e., I need to run a query that selects Products within a partic...

How can I get the previous logged events when a particular logger is triggered?

I need to show the previous 10 events when a particular logger is triggered. The goal is to show what previous steps occurred immediately before NHibernate.SQL logging was issued. Currently, I am logging NHibernate sql to a separate file - this is working correctly. <appender name="NHibernateSqlAppender" type="log4net.Appender.RollingF...

NHibernate: What are the options for fetching multiple entities in one query?

The NHibernate Book discusses very briefly queries that fetch several queries at the same time. They only show how to do this with the native CreateSQLQuery command. Are there any options for fetching multiple entities simultaneously using the criteria or hql APIs? ...

NHibernate Composite Key

I have created a composite key, and it is working, but ideals I would like the separate directly fields in the row class. The current way I'm doing this is the following: private UserPrimaryKey _compositeKey; public virtual UserPrimaryKey CompositeKey { get { if (_compositeKey == null) _composite...

SOAP and NHibernate Session in C#

In a set of SOAP web services the user is authenticated with custom SOAP header (username/password). Each time the user call a WS the following Auth method is called to authenticate and retrieve User object from NHibernate session: [...] public Services : Base { private User user; [...] public string myWS(string username, s...

FluentNHibernate Auto Mappings and ISet in .NET 4.0

How to set up auto mapping to map System.Collections.Generics.ISet<T> correctly? I tried implementing IHasManyConvention, but in intellisense it seems that IOneToManyCollectionInstance does not have anything for that(?) ...

How do I map a one-to-one value type association in an joined-subclass?

I've got a class hierarchy mapped using table-per-subclass, and it's been working out great: class BasicReport { ... } class SpecificReport : BasicReport { ... } With mappings: <class name="BasicReport" table="reports"> <id name="Id" column="id">...</id> <!-- some common properties --> </class> <joined-subclass name="Sp...

Fluent NHibernate Map to private/protected Field that has no exposing Property

I have the following Person and Gender classes (I don't really, but the example is simplified to get my point across), using NHibernate (Fluent NHibernate) I want to map the Database Column "GenderId" [INT] value to the protected int _genderId field in my Person class. How do I do this? FYI, the mappings and the domain objects are in se...