nhibernate

How to map two objects that reference each other in NHibernate?

I have a class that looks like this: public class Job { public Company Company {get;set;} public Job JobForCompanyA {get;set;} public Job JobForCompanyB {get;set;} } The jobs for the two companies will reference each other, for example: var jobA = new Job { Company = Company.CompanyA }; var jobB = new Job { Company = Comp...

NHibernate DTO Parent child relation

Hi I have som entities and now want to make some DTO´s based on there entities using nhibernate. I have a Service - Allocation -Ressource where allocation describes how the ressource is allocated for the service. I want a DTO like ServiceDTO -Name -RessourceDTO where RessourceDTO also has a name. In the examples I have see for NH...

How to return a paged list from a property of a Domain Object using NHibernate and a Repository Pattern

Hi, From the text "The Repository" pattern is a Mediator between the Domain and Data Mapper layers. Cool. So for example, maybe there is a Repository interface and Base Domain Object like so public interface Repository<DomainT> where DomainT : DomainObject{ DomainT Get(Object id); } Then a concrete implementation would be publ...

Nhibernate error when inserting an object with an one-to-one relationship to another object

Hi all, I have a problem with nhibernate when I try to insert an object with an one-to-one relationship to another object. There is a class called Article Mapping file <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"> <id name="ID" column="article_id" type="Int32" unsaved-value="0"> <generator class="native"/> </id> <pr...

Select partial data from a DB table using nhibernate

i have a complex entity, very very heavy. i want to select only the id and the name of this entity from the db for a better performance. how do i do that with nhibernate (or fluent nhibernate). ...

Are NHibernate projection/DTO objects immutable?

If I create a DTo using projection and an import mapping, is the object by default then immutable for NHibernate or is it possible to define mutable=false in the import mapping? ...

What is the CreateCriteria equiv of this line of code:

_session.CreateQuery("Select a.AuLname From Authors a Order By a.AuLname") .List(); I must be drawing a blank here...but I cannot figure out how to return a list of author last names using the session's CreateCriteria method. Getting a distinct list of last names is not a problem as I can use a projection. But that is not what I am t...

NHibernate connection string: how to specify port number and server\instance?

I am replacing my old DAL with NHibernate 2.1. My NHibernate config works on my local dev machine but not on UAT. The UAT database is a cluster setup on a none default port. I am using a standard NHibernate confie file similar to below: <?xml version="1.0" ?> <hibernate-configuration xmlns="urn:nhibernate-configuration-2.2" > <sessi...

Multiple foreign keys to a single column

I'm defining a database for a customer/ order system where there are two highly distinct types of customers. Because they are so different having a single customer table would be very ugly (it'd be full of null columns as they are pointless for one type). Their orders though are in the same format. Is it possible to have a CustomerId co...

Using NHibernate/LINQ to detect and write changed rows from XML files into a database?

Hello all, I have a situation where an XML file contains data similar to some content in database tables, and I would need to update the database to match exactly the contents of that XML file. I am wondering, if using NHibernate, or LINQ to SQL, I am able to do something like this: Load the database content into entity objects. Load ...

Nhibernate: left outer join on subquery

Update take 2 here is the two queries i'm working with (paging is omitted in both queries) i'd like to get the following query SELECT * FROM product LEFT OUTER JOIN ( SELECT * FROM Cart LEFT OUTER JOIN cartproducts ON Cart.Id = cartproducts.Cart_id WHERE Cart.username = 'user' ) AS CartFiltered ON produ...

Mapping empty strings to NULL in NHibernate

I have a SQL Server DB with a recursive table: MyTable: ID : string PrimaryKey Parent: string references MyTable - NOTNULL !! and map with Fluent NHibernate to class MyTable { public virtual string ID {get; set;} public virtual MyTable Parent {get; set;} } My problem is that Parent should be null in my C# app if the column Pa...

NHibernate Conditional Mapping

Hi, I was recently hired at a Software Engineering company and was put in charge of a new project for storing our analytics data. I want to give ORM a shot the mapping doesn't seem difficult but this problem has me vexed. This database will store data for Google Analytics, Quantcast, and any future analytics provider. I was pretty much ...

How to use NHibernate's Session.Criteria with multiple foreign keys?

I'm trying to create a query using NHibernate and searching along multiple foreign keys: The following code works when I'm only searching on one of the foreign keys: ICriteria query = Session.CreateCriteria<TblTeam>() .Add<TblTeam>(x => x.FldUrlSafeName == teamName) .CreateCriteria<TblTeam>(x => x.TblSportsType) .Add<Tbl...

Complex NHibernate Auditing

I'm using the IPostUpdateEventListener interface to do update audit logging now, grabbing the old and new values, then storing each updated field in an "Audit" table and all that jive. Works swell, but there's two last requirements I'm having a hard time fullfilling: Display which employee the update was for. Display the "friendly" nam...

NHibernate: Using value tables for optimization AND dynamic join

Hi all, My situation is next: there are to entities with many-to-many relation, f.e. Products and Categories. Also, categories has hierachial structure, like a tree. There is need to select all products that depends to some concrete category with all its childs (branch). So, I use following sql statement to do that: SELECT * FROM Prod...

Using NHibernate ICompositeUserType with a value type

I have a domain model object which has properties of type System.DateTimeOffset. I'm using a database which doesn't support this type natively, so I'm planning to store it using a column of type 'datetime' and one of type 'smallint'. I've dug around on how to map this using NHibernate components, and found that it could work using an I...

Fluent NHibernate -- Saving Entity with Composite Key

First, I have the following table: CREATE TABLE CustomerHub ( CustomerId INT NOT NULL, HubId INT NOT NULL ) Which I have mapped to the this entity: public class CustomerHub { public int CustomerId {get;set;} public int HubId {get;set} //GetHashCode, Equals, Etc... } Using this mapping: public class CustomerHubMap :...

NHibernate: How to insert a new Set member after containing object is created?

I have a Person class which has a Tags property public virtual System.Collections.Generic.List<Tag> Tags { get; set; } which contains a collection of Tag class objects. Given the system design, the instance of the Person class is created initially and then at a later time the user can add tags to a Person. Being new to NHibernate I ...

How do I serialize all properties of an NHibernate-mapped object?

I have some web methods that return my objects back as serialized XML. It is only serializing the NHibernate-mapped properties of the object... anyone have some insight? It seems to be that the web methods are actually serializing the NHibernate proxies instead of my classes. I've tried using [XMLInclude] and [XMLElement], but the pro...