nhibernate

One-To-Many , Many-To-One recursive Relationship in NHibernate

I have a use-case in my app where I need the first two levels of my object tree. I have an object called Player which has a list called CheckIns that holds a many-to-one connection to Player as an object reference when I execute the Query I get back a seemingly endless chain of Player->CheckIns->Player->CheckIns and so on.. What I nee...

Mapping a backing field, that has a diferent type from the respective property, using Fluent NHibernate

I need to persist this class on database using Fluent NHibernate: public class RaccoonCity { public virtual int Id { get; private set; } public virtual DateTime InfectionStart { get; private set; } private IList<Zombie> _zombies = new List<Zombie>(); public virtual IEnumerable<Zombie> Zombies { get { retu...

How do you clone and compare tables in NHibernate?

I have an application where I want to take a snapshot of all entities, creating cloned tables that represent a particular point in time. I then want to be able to compare the differences between these snapshots to see how the data evolves over time. How would you accomplish this in NHibernate? It seems like NH isn't design for this type...

How to build a tree in C# given just the child elements?

I have a set of elements that belong to a tree. I only care about the ancestors, I don't care about the children. For example I want the tree to look like this: Barbeque Supplies* Household cleaning Supplies Air fresheners 1. Car Airfreshner* Paper Towels* Utensils Forks* The only input I'm given are the starred elements. So I...

is there a way to do a reverse lookup in nhibernate?

i have two tables: Components ComponentDependencies ComponentDependencies has two columns: ComponentId and ComponentDependencyID. (both foreign keys into Id field of Component table. i am using fluent nhiberate and i have my component object having: public virtual IList<ComponentDependency> Dependencies { get; set; } and in my C...

Unnecessary updates with bidirectional mapping.

Hi, I am using Fluent NHib which generates the mappings bellow. I read this: http://www.progware.org/Blog/post/NHibernate-inverse3dtrue-and-cascade3dsave-update-demo.aspx but I still cannot figure it out. The only difference is that I am using GuidComb for PK. Parent: <bag access="nosetter.camelcase-underscore" cascade="save-update" i...

NHibernate Eager Loading - Lots of unrelated data

My members will have the ability to customise their profile page with X amount of widgets, each widget displays different data such as a list of music, list of people they are following etc. Several widgets include: - List of media they have uploaded - List of people they are following - List of people following them - Html/Text wid...

Why does calling Session.Clear() cause this test to fail?

The following is a simple test of a repository against FluentNHibernate-1.1.0.685 (NHibernate-2.1.2.4000). The Session and NH config are provided by the test fixture. [Test] public void ShouldEdit() { var employee = CreateEmployee(); session.Clear(); var changedEmployee = _testRepository(employee.id); changedEmployee....

"many-to-one" within component problem NHibernate

With the following mapping, BillingAddress.Country is mapped correctly but ShippingAddress.Country is always null. Maybe it's because of equal properties name? but they are different objects... Any idea how to fix it? Thanks ahead. <?xml version="1.0" encoding="utf-8" ?> <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="K...

Complex SQL Query to NHibernate DetachedCriteria or HQL

Hi, I have the following SQL Query returning the results I need: SELECT Person.FirstName,Person.LastName,OrganisationUnit.Name AS UnitName, RS_SkillsArea.Name AS SkillsArea, Activity.Name AS ActivityName, Activity.CLASS, Activity.StartsOn, Activity.EndsOn, SUM(ActivityCost.CostAmount) / NULLIF( ( SELECT COUNT(Registration.A...

NHibernate query against nested class

I'm using NHibernate. I have a class which has a nested type. Is there any way, using NHibernate, to query against the nested type, asides from using a native SQL query? Nested classes are not allowed in HQL currently. EDIT: The outer class has an IList of nested class instances. ...

Tips for fixing dll version problems in .NET.

Hi all I've just got to grips with the basics of NHibernate, and while refactoring my data access and domain layers I thought I might as well get cute and start using dependency injection for the data access layer. Unit testing here we come! I thought since NHibernate uses loads of Castle dlls I might as well use Castle Windsor for th...

NHibernate FlushMode: How do I set up NHibernate for automatically updating an entity

Hi! After I retrieve an entity, I change a property of it. Then I retrieve the same entity. How do I say Nhibernate, that it shall update the entity before it loads the entity? Here the code: EmployeeRepository employeeRepository = new EmployeeRepository(); Employee employee = employeeRepository.GetById(4); employee.LastName = "TEST...

NHibernate Linq : Contains Statement

As an example, let's say you have a class like such **Person** int PersonID string PersonName BusinessLocation Locations **BusinessLocation** string city string state List<int> ZipCodes (saying that the locations may exist in multiple zipcodes) (also ignoring that zipcodes should be strings instead of ints, this is just an example) ...

Should NHibernate generate SQL for GUID parameter without quotes?

Sql Server 2008 R2 Express. NHibernate 2.1.2.4. I get SQL like: SELECT customer0_.Id as Id1_0_ FROM customers customer0_ WHERE customer0_.Id=@p0; @p0 = 11111111-1111-1111-1111-111111111111 ...which returns 0 records even though there is Customer in there with that Id. The SQL Server column datatype is UNIQUEIDENTIFIER. <session-f...

Skipping an new/transient NHibernate entity's ID generator strategy when an ID is already provided

Hi all Just a quickie ... I have the following ID generator strategy for one of my mapped classes: <id name="UID" type="System.Guid"> <column name ="UID" sql-type ="uniqueidentifier" /> <generator class="guid.comb" /> </id> The entity in question is involved in synchronisation / merging behaviours from which it is necessary t...

NHibernate : pattern for returning fully loaded instances from repositories

Hi all As part of my endless NHibernate-inspired DAL refactoring purgatory, I have started to use the Repository pattern to keep NHibernate at arms length from my UI layer. Here's an example of a Load method from a repository. public StoredWill Load(int id) { StoredWill storedWill; using (ISession session = NHibernateSessionFactory...

NHibernate: how to express a specific "group by" query with criteria

Question: What are the criteria/projections that can generate a following query? SELECT SUBSTRING(Name, 0, 1) FROM Person GROUP BY SUBSTRING(Name, 0, 1) (Obviously this one is easier with DISTINCT, but I'll need counts later, when I fix this one). My approaches: My main problem here is with constants, because if I use Projecti...

NHibernate: help translating an hql query to use criteria api instead

I have the following hql query which I'd like to switch over to the criteria API select a.Id as Id, a.Name as Name, a.ActiveStatus as ActiveStatus, dbo.GetActivityStartDate(a.Id) as StartDate, dbo.GetActivityEndDate(a.Id) as EndDate, coalesce(ac.Id,0) As CategoryId, coalesce(ac.Name,'') As CategoryName from Activity as a left oute...

Nhibernate one-to-many lazy loading not working as expected.

Consider the following scenario: Class A has a one-to-many relationship to Class B. Class B has a many-to-one relationship to Class C. class A { IList<B> BList {get;set;} } class B { C CMember{get;set;} } class C { //null } If I load class B from the database using something like IList<B> result = query.List<B>(); every...