nhibernate

NHibernate.NonUniqueObjectException within a transaction (using CSLA.Net)

I am pretty new to both NHibernate and CSLA.NET, and I'm running into an issue where I'm essentially needing to save the same row in the database twice, within the same transaction (and therefore, session). I've read the other questions on SO w.r.t. the NonUniqueObjectException, as well as done a lot of googling, but I can't seem to make...

Optimize SQL join query for NHibernate

Take a fairly simple domain model Orders, items and shipments where the Order is a root entity and shipment is a root entity. I want to look up all shipments for a given order. The query is pretty straight forward but I'm seeing undesired behavior with NHibernate. The Model public class Order { public Order(){ Items = new List<LineIte...

NHibernate mappings

Hi If I have a customer table with fields : Address1, Address2, Address3 - Is it possible to map these fields into one array of strings? So from an implementating point of view I would want to call Customer.Address[0] ? Thanks ...

How to map this in Fluent.NHibernate

I'd like to get this output from fluent.nhibernate <map name="Dict" table="TABLE"> <key column="ID_USER" /> <index-many-to-many column="ID_TABLE" class="TableClass" /> <element column="COL" type="Int32" /> </map> where class has: public class User { public virtual IDictionary<TableClass, int> Dict { get; protected set; } }...

Can you explain inheritance in Nhibernate to me?

Im having a hard time understanding how inheritance works with NHibernate, with regards to mapping with .hbm.xml files. ...

Fluent NHibernate Automapping Bi-directional relationships

Hi, I am trying to automap my domain model using fluent nhibernate. In this particular case I have a bidirectional one-to-many relationship that i need to map. Problem is that it doesn't automatically realize it as a bidirectional relation but as two different relations altogether and creates a separate foreign key for each. How do I t...

NHibernate 2.1: LEFT JOIN on SubQuery with Alias (ICriteria)

Hello, I am basically trying to create this query with NHibernate ICriteria interface: SomeTable 1:n AnotherTable SomeTable has columns: PrimaryKey, NonAggregateColumn AnotherTable has columns: PrimaryKey, ForeignKey, AnotherNonAggregate, YetAnotherNonAggregate SELECT table1.NonAggregateColumn, subquery.SubQueryAggregate...

How do you do joins in hibernate activerecord?

How do I do a join that would return me results similar to- SELECT * FROM Project LEFT JOIN ProjectRegion ON ProjectRegion.id = Project.projectRegion I currently use the syntax- Project[] projects = Project.FindAll(); My tables are setup with ActiveRecord/hibernate as follows - [ActiveRecord] public class ProjectRegion...

NHibernate questions - modifying this example for Fluent NHibernate

Hi, I'm new to NHibernate... I have been following this NHibernate Tutorial from Gabriel Schenker : http://nhforge.org/wikis/howtonh/your-first-nhibernate-based-application.aspx However, this tutorial uses hbm files. I would like to know - what do I need to do to modify the hepler class below (which creates a session factory) so that...

Fluent mapping - entities and classmaps in different assemblies

When using fluent configuration to specify fluent mappings like this: .Mappings(m => m.FluentMappings.AddFromAssembly(typeof(UserMapping).Assembly)) At the moment I am getting a "NHibernate.MappingException : No persister for" error. Is it a problem that my Entities and my ClassMaps are in different assemblies? Presumably AddFromAss...

NHibernate Second Level Cache With NHibernate Linq Provider 1.0

How to enable NHibernate Second-Level Cache with NHibernate Linq Provider 1.0 ? Second-Level Cache seems to work only with ICriteria usage. ...

Mapping a single row result through a linking table with filter in FNH

Excerpts from an existing schema: User Table: PK int UserId, string UserName, etc Vendor Table: PK int VendorId, string VendorName, etc UserVendor Table: PK int UserId, PK int VendorId, PK bit IsPrimary //note the composite key There is no FK between User and UserVendor (don't ask, it's a legacy database). I'd like to produce a Us...

Can I have a collection of IUserType instances?

Is it possible to have a collection of entities that are mapped via an IUserType? For example: class Foo { public int Id { get; set; } public ISet<Special> Items { get; set; } } class Special { public Special(string columnValue) { _val = columnValue; } public override string ToString() { re...

NHibernate Conversation per Business Transaction and Identity Keys

I would like to implement the conversation per business transaction pattern in a WPF application as described here. Unfortunately this application has a large existing database using SQL Server generated identity keys in all tables. I know that adding a new object to an NHibernate session will cause it to be inserted if it has an ident...

NHibernate: IUserType value from external (web) service

Suppose I have public class Product { public IList<Item> Item { get; set; } } Now, the problem is that Item can only be loaded from some web service. It's not in the database. So as is I have the only choice to do public class Product { public IList<int> ItemIds { get; set; } } and then somehow load Items manually. But I ...

NHibernate removes DAL?

Am I right that using NHibernate (or any other ORM) removes the necessity of DAL? Or not? ...

Weird ASP.NET (MVC) error: "Unable to load one or more of the requested types."

Hi, I'm getting weird error and I have no idea how to resolve it. I've got an ASP.NET MVC website which works fine but once I publish it to a server I get: "Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information." Stack Trace: [ReflectionTypeLoadException: Unable...

NHibernate commit db changes without explict call to save or update

I use Nhibernate 2.0 in ASP.NET. I start the transaction at the begging of the page and commit the transaction at the end. During the page: - I get an object - I change the object property - I validate the object - if validation is ok I call save-update on that object - if validation is wrong i don't make any call to save-update on that ...

Criteria building nhibernate

Hi, I was wondering if someone could help with an example criteria for nhibernate. I think I've got my head around fairly basic things, like finding records in a given table who's field matches a certain value etc. Where I'm currently tripping up is where you have a table with a foreign key for another table, and attempting to find rows ...

Mapping a collection of foreign keys in nhibernate

I have tables like this: tblUsers int UserID string UserName tblUsersInRoles int UserID int RoleID tbleRoles int RoleID string RoleName A user can be in many roles. Is there a way to create my mapping file for my users so that my users object contains a list of Roles? I've figured out to do it so that I have a list of RoleID's lik...