nhibernate

Is there a way to return the primary key of inserted record with NHibernate?

Well, the question kinda nails it down. I'm currently doing something like this: using (var session = _sessionFactory.OpenSession()) { using (var transaction = session.BeginTransaction()) { Car newCar = new Car(); newCar.name = "Jeep"; session.Save(newCar); transaction.Commit(); } ...

a little help with NHibernate mapping over legacy database?

I am re-writing an app that sits over a legacy database. I'm using NHibernate and I've had problems getting some mappings to work and would like some help. First, the table structure: Tech: Id FirstName LastName User: TechID Username The "User" table has no primary key. Foreign keys are no enforced at all. TechId is support to corre...

How do I use Fluent Nhibernate many-to-many for optimal performance?

I have a product table that has a many-to-many relation to itself (using a two-column many-to-many table) and I have set it up in Fluent NHibernate with the following code: public class ProductConfiguration : ClassMap<Product> { public ProductConfiguration() { Table("Product"); Id(p => p.Id).GeneratedBy.Guid(); ...

nunit on release build: "Common Language Runtime detected an invalid program."

I upgraded our software from vs2008/.net 3.5 to vs2010/.net 4.0. All third party libraries (most relevant: nhibernate 2.1.2, spring 1.3.0, nunit 2.5.2) are still compiled using vs2008. When I run the unit tests for the debug build of our software, everything works fine. On the release build, nunit reports exceptions on 33 of 228 tests: S...

NHibernate - How to fetch conditional data from database using hbm file mapping

Hello, Currently I am using many-to-one element in hbm file to fetch the data object from database like following.... <property name="ContactId" length="4" /> <many-to-one name="DefaultContact" column="ContactId" class="Models.Contact" update="false" insert="false"/> This code is fetching the data properly, but no...

NHibernate MappingException: Could not compile the mapping document

Hi all On my dev web app NHibernate is working just dandy. When I precompile and deploy the site, I get a MappingException when the SessionFactory is created. Here's some info from the trace: NHibernate.Cfg.Environment 2010-07-15 09:20:59,577 [7] INFO NHibernate.Cfg.Environment [(null)] - NHibernate 2.1.2.4000 (2.1.2.4000) 0.452...

NHibernate - "In" query with composite id

I'm trying to perform an "in" query on a collection of id objects (implemented as a simple class with two integer id members) which are mapped as composite-keys and I'm seeing some strange results when I query using the criteria api using Restrictions.In and using NHibernate.Linq using idList.Contains Here is a sample usage: Public...

Automatically update both end of a one to many relationship with NHibernate

Hello, It is of a newby question, so sorry in advance. I'm using fluent NHibernate and get a strange behavior on it. I have two classes that look like that (simplified) : public class Group { public virtual int Id{get;protected set;} public virtual String Name{get;set;} public virtual List<Person> Persons {get; protected ...

NHibernate many-to-many relationship question: can select, can't update

Each user has a list of roles: <class name="User" lazy="false" table="Users"> <id name="Id" type="int"> <generator class="native"/> </id> <property name="Name" /> <bag name="RoleList" table="User_Role" inverse="true" lazy="false" collection-type="Roles"> <key column="UserId" foreign-key="Id"/> <many...

How do you return certain properties from a linq query, rather than complete objects?

Hi all I've just downloaded the Linq provider for NHibernate and am just a little excited. But I don't know Linq syntax that well. I can return whole objects from a query like this: var query = from foo in session.Linq<Kctc.BusinessLayer.Domain.Case>() where foo.CaseNumber > 0 select foo; And I ca...

NHibernate dialect for Interbase

Hi all I do a good deal of work with an Interbase server. I would like to develop a data access layer for it using NHibernate but there isn't a readymade dialact for Interbase. Does anyone know, is there an NHibernate dialect which is used for generic ANSI-only database work, or if any of the existing dialects will work okay with Inter...

CSV identity fields: nHibernate oddity or db design error?

I've inherited a database and know an nHibernate engine was used on top of it. Inside the database I see CSV values representing multiple identities instead of "proper" link tables being used for primary and foreign keys. For example one tuple looks like this: PersonID, int: 1 Name, varchar: John Smith Edus, varchar: "76,5262,...

Fluent NHibernate one-to-many Cascade.SaveUpdate() blocks updates to entity

We have an Enrollment object that has a Student object and the Student object has many Enrollment objects. If I leave off the Cascade.SaveUpdate() from the Enrollment's Student reference, updates to the Student table do not execute, but updates to the Enrollment object succeed. But if I add the Cascade.SaveUpdate() on the Enrollment's ...

Default event listeners in NHibernate

In order to workaround a bug in NHibernate (see here if you're interested), I would like to replace the default flush event listener in NHibernate with my overridden class. I configure my event listeners programmatically (rather than in XML), but I'm not sure how the default event listeners are registered. For example, in the following...

nHibernate criteria for reversed LIKE

I have the following two entities: public class Entity1 { public IList e2 { get; set; } } public class Entity2 { public string Title { get; set; } } I only have repository for Entity1, I know I can do a LIKE query with the following criteria: criteria.CreateAlias("e2", "e1e2").Add(Restrictions.LIKE("Title", "needle", Match.Anyw...

How to handle NHibernate sessions in an ASP.NET WebForms application?

I see there are 2 possible scenarios as to the session handling: Open one single ISession per request. Open it at request start and close it at request end. Open one ISession per conceptual "unit of work". Many sessions are created for a request. The approach #1 is the one I'm doing now. I'm a little bit worried about it because, alt...

How do I debug slow NHibernate Select query?

I'm doing a simple query on the database, a search on two columns. I have an index on the columns. When I do the search in SQL Server Management Studio, it takes only a few milliseconds to complete (always less than 10). When I do the same query in NHibernate, it takes over 30 seconds. I've profiled the query, and the generated SQL is fi...

How to use Fluent NHibernate in N-Tier application?

I'm trying to adopt Fluent NHibernate with my project, currently I can get data from database, when I'm at application server, data is include its PK but when I return this data (as List) to client all of its PK is loose. How can I fixed this problem? Update My POCO class is below: PKs are CountryCd and CityCd public class coCity { ...

NHibernate HQL vs CriteriaAPI vs QueryOver. Performance.

Hi, What are the performance differences between the hql and criteriaApi and QueryOver? Are there any situations where one is faster or slower than the other? Edit: I extended the question with QueryOver. ============================================= Well, I am not sure which response to mark as answer so I will mark posts with most ...

Association in Nhibernate with Lazy true

Hi All I am working in a project that's work with N Hibernate. Due to performance issues and increasing in complexity of the project we need to do association manually in our code.As we all know for that we have to set lazy property true. What i want know that, is their any way to do association with set lazy property true.We have alrea...