nhibernate

NHibernate with SQL Server - How to Process Next New type of Environment

I have an application (ASP.NET MVC) that uses a Next New method to get the next new piece of work. The user clicks on a Next New button, and my NHibernate code would go fetch the next piece of work with an Active status. As the number of users has increased, we have seen an issue arise where 2 users can get the same piece of work. This ...

How does Query caching improves performance in nHibernate?

How does query caching works and how does it improves performance in nHibernate? ...

Why both NHibernate OnPreInsert and OnPreUpdate methods get called for an object

I use the NHibernate OnPreInsert and OnPreUpdate events in a PreSaveEventListener to set the CreatedDate and ModifiedDate of my entities. The problem is, there are two entities for which both events get triggered when I first create them. This causes an issue because the entity state does not get saved after the OnPreInsert event, so the...

How do I configure NHibernate Profiler so I can enable/disable it without changing code?

I've been trying to follow the directions on the NHProf site but can't seem to make it work. What am I missing? I put a log4net configuration section in my web.config: <configSections> <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net/> ... </configSections> ... <log4net> <appender name="NH...

Problem with nhibernate linq Expand() statements results not being cached with rest of results

Hi All Some more cache related problems. I am having a problem getting the results of associated or child entities to be loaded into the nhibernate cache along with the root entity when using the Expand() method. So the following: var query = session.Linq<Promoter>(); query.Expand(x=>x.PromoterType); query.Query...

NHibernate mapping of one class containing 2 references to the same entity

I have a person class, then have a family class where I have a property Father and a property Mother of type Person. I have a database table for Person and a Family table containing FamilyId, FatherId, MotherId where FatherId and MotherId is foreign keys for PersonId in Person table. How would you go about to map this in NHibernate? ...

Constructing query against IUserType in NHibernate

How can I construct a query against an custom IUserType field in NHibernate? More specifically: I'm working on a brownfield application. I have a field in the database called "State" which contains a char representing what state a given object is in. In my code I want this to be represented as an enum so I've created an enum with a va...

SQL Query improvement - Select with max and groupby

Problem Given the following two tables, I'd like to select all Ids for Posts that have their most recent (i.e. last) comment made in the given time span (e.g. Feb 2010). The result of the query should only return Post ID 1, since the most recent comment for Post ID 2 is outside the range of the time span filter. Question I've c...

T-SQL to HQL (NHibernate)

I have the following T-SQL: DELETE FROM Table WHERE UserId=@UserId AND TableId NOT IN (SELECT TOP 10 TableId FROM Table WHERE UserId=@UserId ORDER BY DateColumn) What is the NHiberante equivalent? Cheers. ...

nhibernate interceptors with domain context

Hi Is it possible (in a clean fashion) to create an audit interceptor in hibernate 2.1 and pass in a domain context to it? What I would like to achieve is to set a Date Time (can be done easy peasy - found loadsa articles after a quick google), but setting an object e.g. a user who created the item, or altered an entity I have yet to f...

NHIbernate SysCache2 and SQLDependency problems

Hi, I've set enable_broker on my SQL Server 2008 to use SQLDepndency I've configured my .Net app to use Syscache2 with a cache region as follows: <syscache2> <cacheRegion name="BlogEntriesCacheRegion" priority="High"> <dependencies> <commands> <add name="BlogEntries" command="Sel...

Linq to NHibernate returns different results than HQL?

I have this basic entity setup: public class Instrument { public virtual int Id { get; set; } public virtual Guid? InstrumentGuid { get; set; } public virtual string FIPSCode { get; set; } public virtual IList Names {get; set;} } public class Name { public virtual int Id {get; set;} public virtual string Name {g...

NHibernate Equality: How do I ensure only one row is persisted from many "equal" .NET objects?

How can I get the following test to pass with NHibernate? I thought it was enough to simply override Equals and GetHashCode in the entity class for this to work the way I want it to. Obviously for "Point" objects, which are quite trivial, it's silly to persist multiple rows for identical coordinates. I have two point objects that have i...

WCF/S#arpArch: underlying ISession is closed after the first call within a request

I know the use of WCF in SA is deprecated because it will move to SA Contrib. But until it has, I guess I have to use the support in SA. That said, I have a problem with the underlying NHibernate session being closed after calling a WCF service. My repository's DbContext.Session is closed after the first call so I cannot call my service...

NHibernate many to many mapping error - NHibernate.MappingException: Could not determine type for:

Hi, I am having a problem when trying create a many to many mapping. Consider the following tables: CREATE TABLE [dbo].[student] ( [Id] INT IDENTITY (1, 1) NOT NULL, [Name] NVARCHAR(255) NOT NULL, -- Some other stuff... ) CREATE TABLE [dbo].[Subject] ( [Id] INT ...

NHibernate entity loose coupling

Let's say I have an entity called MyItem. It can be included in many "parents", like SomeCollection and SomeOtherCollection. Because it can be included in many parents, and since I don't want MyItem to know about the parents, I'd like to not have any properties in MyItem referencing a parent. And since a parent, like SomeCollection, can...

Generate identity from seed table in Fluent NHibernate

I need to generate an identity from a column in a seed table and increment the value in that column. e.g Seed Table: name "analysisid" id 1 Analysis Table: id name description On the analysis mapping I need to ensure that the id is taken from the seed table and on inserting an analysis the analysisid of the seedid is up...

Concurrency Violation in NHibernate( c#) example

For quite some time , I was reading about the optimistic concurrency in NHibernate. If what i understood was correct then the below sample should hold good. Consider two transactions T1 and T2. When T1 and T2 are done simultaneously , the state(DB entries) gets updated with the values of the most latest update.(T1 or T2). Though it ...

Fluent NHibernate Automapping DDL is missing foreign key reference column

I've created the following classes and use the automap functionality of fluent to automatically generate my database: public interface IBaseClass { int Id { get; set; } DateTime CreatedOn { get; set; } } public interface IApplicant : IBaseClass { string Firstname { get; set; } string Lastnam...

Join tables with nested select count and group by in Nhibernate HQL

I have post, vote and comment table. Each post can have N votes and N comments. I have been trying to find a way to do this query using Nhibernate HQL with no success. SELECT P.Id, P.Title, P.TextDescription, ISNULL(V.TotalVotes,0), ISNULL(C.TotalComments, 0) FROM Post P LEFT JOIN (SELECT PostId, count(PostId) as TotalVotes...