nhibernate

Mapping items-itemtags-tags tables with nhibernate

Lets say i have this database design: Items Id Name Desc ItemTags ItemId TagId Tags Id Tag And i want to map it to the following class class Item int Id string Name string Desc IList<string> Tags Please note that I don't want to declare class Tag, i just want the Item class to have list of strings that repre...

Strange NHibernate exception

Hi I'm getting a strange NHibernate exception when I try and create a SessionFactory. I've narrowed down the exception 'Unable to cast object of type 'NHibernate.Mapping.Bag' to type 'NHibernate.Mapping.IKeyValue' to the following mapping on the Company object: <bag name="Images" cascade="none"> <key column="CompanyId" property-ref...

NHibernate ManyToMany and eager loading: strange resultset for SetFetchmode combined with SetResultTransformer and SetMaxResult

I've got a many-to-many relationship which I try to fetch eager: *.CreateCriteria(typeof(Class1)) .SetFetchMode("Class2", FetchMode.Eager) .SetResultTransformer(new DistinctRootEntityResultTransformer()) .SetFirstResult(20) .SetMaxResult(10) .List<Class1>(); I'd like to have rows 20-30 returned, but instead I've got 12-18. Why? Becaus...

How to map Items which its SubItems are in the same Table with Nhibernate?

Hi, I am trying to build a messaging system and for this i have the table definition below Message Id From To Body ParentId // Subcollection, i want to get Asnwers (Message.ParentId== Message.Id) IsRead and i have this in the Message.cs IList<Message> Answers; I have tried this but it gives me all the messages and all the answers...

NHibernate - map same entity to different tables within the same database.

Lets say we have an Employee entity composed of a few other entities, such as a one-to-many addresses and contacts, and a few fields (name, age, etc). We mapped this entity out and can use it just fine, saving each piece out into "Employee", "EmployeeAddresses", and "EmployeeContacts" tables. However, we use pretty much all of this empl...

NHibernate HQL's Equivalent to T-SQL's TOP Keyword

What is NHibernate HQL's Equivalent to T-SQL's TOP Keyword? Also what is the non-HQL way for saying give me the first 15 of a class? ...

NHibernate one-to-many problem

I have a Vessel object that has a one-to-many relationship with a VesselDetail object. When I add a VesselDetail object to the Vessel object and try to save the Vessel object, it seems NHibernate does not add the foreign key when inserting the VesselDetail object. Where am I going wrong here ? I just cannot figure it out. Error messag...

Nh.Burrow with WCF

Hello, After implementing Nh.Burrow in an asp.net application, I was wondering how to do it for a WCF-service. My first idea was to put a the BurrowFramework().InitWorkSpace(); in each method and set the InstanceContextMode to per Call on these methods. Now I have two questions: Are there better methods to combine Nh.Burrow with WCF?...

NHibernate - SELECT DISTINCT equivalent for a page filter - Northwind

Lets say you are working in SQL 2005 with a copy of Northwind database installed. Your working on an ASP.NET application with an Employees "browse" page. At the top of the page you have a "Title" filter where you would like to display these 5 choices in a dropdown: [ALL] Vice President, Sales Sales Representative Sales Manager ...

NHibernate mapping: Entity1 -> ValueType1-> Entity2

I have a following domain model: Entity1 -> ValueType1-> Entity2 How can I write the mapping file to represent the above situation (while retrieving Entity1)? PS: I know I can use component tag when value type does not refer to another entity (in this case Entity2). Thanks ...

NHibernate bulk insert or update

Hi I'm working a project where we need to process several xml files once a day and populate a Database with the information contained in those files. Each file is roughly 1Mb and contains about 1000 records; we usually need to process between 12 and 25 of these files. I've seen some information regarding bulk inserts using NHibernate b...

NHibernate / ActiveRecord: How to set foreign key without getting entire object?

Let's say I've got the following ActiveRecord class: [ActiveRecord] public class Account { ... [BelongsTo("CustomerId")] public Customer Customer { get; set; } } Currently, to set the value of the CustomerId field I have to get the entire Customer object from the database and assign it to the Account: Customer customer =...

How to do ORM for this situation?

I have the two following tables (SQL Server): **IndexValues** IdIndexValue int (PK) Value varchar(2000) IdIndex int (FK for Table Indexes) IdDocument int (FK for Table Documents) **IndexValuesLists** IdIndexValueList int (PK) IdIndexValue int (PK with IdIndexValueList, FK for Table Indexes) Explaining a little, the second table grou...

When is the last moment I can return an exception to a client in WCF?

Let's say I have this in an implementation of IInstanceProvider: public void ReleaseInstance(InstanceContext instanceContext, object instance) { try { unitOfWork.Commit(); } catch (Exception) { unitOfWork.Rollback(); throw; } finally { unitOfWork.Dispose(); } } That t...

Fluent NHibernate - how to configure for oracle?

Almost certainly a stupid question but I can't find the answer anywhere. In the Getting Started tutorial the database is SQLite and so his session factory creation is done using the SQLiteConfiguration class in the FluentNHibernate.Cfg.Db namespace Great! But I don't see a Configuration class for using an Oracle database. How do I do...

Where can I find a good NHibernate and ASP.NET MVC Reference Application

Where can I find a good NHibernate and ASP.NET MVC Reference Application? I downloaded S#arp and this seemed to be a lot more than I needed (IOC and CodeGen via T4). I might work my way up to this later, but I need something smaller at first. Any simple examples? I just want to pick up how NHibernate Session handling works in ASP.NET MV...

NHibernate Eager loading multi-level child objects

I have a hierarchy of objects, Order, Contact, Address: public class Order { public virtual Contact BillingContact { get; set; } } public class Contact { public virtual Address Address { get; set; } } I want to query an order by id, and eager load the billingcontact, along with it's address. var criteria = DetachedCriteria...

Why can't I create child objects in Hibernate/NHibernate - tricky mapping problem

I think I have tried every thing to get this to work but to no avail. Any hints/help much appreciated. The following parent-children relationship causes the following error on creation of the parent. could not insert: [Kanpeki.Domain.CalEvtCatergory][SQL: INSERT INTO tb_calEvent_catergory (catergoryID, parentID, catergoryType, catergor...

Fluent NHibernate: How to map a db integer to a datetime column?

I have a class public class Site { public DateTime SiteMonth {get; set;} } in the database the SiteMonth is represented as an integer in yyyymm format. Is there a way to map this in NHibernate without introducing a new property on my Site class? ...

NHibernate one-to-many

Hey, I have a pretty simple NHibernate setup: an Item object which has a collection of ItemDetail objects. One-to-many relationship between them. In my web application, I'm writing code similar to: item.Details.Add(new ItemDetail { Item = item, Text = "blah" }); itemRepos.Save(item); This all works well. However, now I'm writing a s...