nhibernate

How to deserialize Enumerable.ToList<>() to List<>

I'm trying to build an object that looks something like this: public class MyObject { private IList<AnotherObject> items; public List<AnotherObject> Items { return items.AsEnumerable().ToList<AnotherObject>(); } } I'm using NHibernate as my DAL and have it mapping directly to the items field and all that wo...

Sorting linked collection in Nhibernate query

This is partly related to this. I'd like to find a way to sort of a linked (HasMany) collection result directly in the Nhibernate query. ICriteria criteria = Session.CreateCriteria(typeof(PortalPage)); criteria.CreateAlias("PartialViews", "vc"); criteria.AddOrder(Order.Asc("vc.ColumnNumber")); criteria.Add(Property.ForName("Url").Eq...

NHibernate Mapping File Help

Hi All NHibernate noob here. Looking for advice on how to map the following common scenario: [Store] id pk Name [StockItem] id pk Name [StockItemStore] id pk StockItemId fk StoreId fk ParLevel I have created a domainmodel that allows various StockItems to be assigned to various Stores via the StockItem Entity using a AssignToStore(S...

MySql schema generation with NHibernate

I've used following code to generate database creation script Configuration configuration = new Configuration(); configuration.Configure(); SchemaExport schemaExport = new SchemaExport(configuration); using(TextWriter stringWriter = new StreamWriter("create.sql")) { schemaExport.Execute(false, false, false, true, null, stringWriter);...

Nhibernate Get and Load.

Hello I am fixing a codebase using NHibernate and I found out that instead of using Get or Load to find entities by ID they were using a query. Like : session.CreateCriteria(typeof(T)).Add(Expression.AllEq(propertyNameValues)).List<T>(); where the propertyNameValues is a IDictionnary containing "ID" and the id value. Trying to ...

Automatically truncating strings in NHibernate / SQL Server

I have a nvarchar(2000) column in a SQL Server 2005 database, and have mapped this into NHibernate as: <property name="Query" column="`Query`" type="String" length="2000" not-null="false"/> The DTO class just presents a string property: public virtual string Query { get; set; } If I set the query to a string of > 2000 character...

NHibernate and multiple databases

I'm trying to solve pretty easy problem. I want to establish connection to 2 totally different databases ( but both mysql ). Now I tried to solve this by creating multiple config files and then creating multiple sessions. Everything works until I reached relations. I have 2 tables in 2 databases: db1 - News db2 - News_Authors I add...

Only updating filled in properties

Is there a way to have NHibernate only update the fields that don't have the default value filled in? Say we have this simple class: public class Person { public int Id { get; set; } public string Name { get; set; } public int Age { get; set; } } We also have a standard NHibernate mapping using properties for each field an...

Linq for NHibernate and fetch mode of eager loading

Is there a way to set the fetchmode to eager for more than one object using linq for nhibernate. There seems to be an expand method which only allows me to set one object. However I need to set it for more than one object. Is this possible? Thanks ...

NHibernate SQL creation causes error

I have 2 classes named Order and Orderrow. I use NHibernate to get a join on it. When running NUnit to test the query, I got an ADOException: Logica.NHibernate.Tests.NHibernateTest.SelectAllOrdersFromSupplierNamedKnorrTest: NHibernate.ADOException : could not execute query [ SELECT this_.OrderId as OrderId1_1_, this_.CreatedAt as Creat...

Mapping and query for three way many-to-many-to-one in NHibernate

UPDATE: I mistakenly pasted query code from the wrong overload. At the bottom is the fixed code Hi, let's say here's my domain. I'm tracking some sport Events like say car races. Each Race has Racers who take part in the race. Racer is a Driver in particular Race (it has the Driver, start lane, run-time, etc). Driver has things like...

How to create a Multi-Column Index or Unique Constraint with NHibernate

How to create a Multi-Column Index and/or Unique Constraint using NHibernate Mapping or Fluent NHibernate. ...

Using NHibernate to query with NOT IN in the WHERE clause

Take this query as an example: select * from publisher where id not in ( select publisher_id from record where year = 2008 and month = 4 ) Can anyone help me on how I could build and run this query using NHibernate? Assume that I have 2 classes: Publisher and Record. Thanks ...

VIEWS and Fluent NHibernate?

It's possible to map a VIEW using Fluent NHibernate? If so, how? ...

NHiberate nested transaction blocking

I have an NHibernate Transaction that does some work and makes a call to a legacy method which uses DBTransactions to call several Stored Procedures. If any of these legacy method calls fail then the NHibernate Transaction should rollback. The problem is that the Legacy methods are using data in the database that the NHibernate transact...

How can I map a nullable enum in NHibernate?

I have been unable to persist a nullable enum using NHibernate with Fluent NHibernate configuration. NHibernate attempts to save a string representation of the enum and I get the error System.Data.SqlClient.SqlException: Conversion failed when converting the nvarchar value 'VGS' to data type tinyint. The property is defined as publi...

How am I supposed to query for a persisted object's property's subproperty in nhibernate?

I'm feeling dumb. public class Uber { public Foo Foo { get; set; } public Bar Bar { get; set; } } public class Foo { public string Name { get; set; } } ... var ubercharged = session.CreateCriteria(typeof(Uber)) .Add(Expression.Eq("Foo.Name", "somename")) .UniqueResult<Uber>(); return ubercharged; This throws a "could not r...

ORM and database indexes

What approach do you have towards creating and maintaining database indexes when using ORM such as NHibernate/Hibernate. Since the ORM is generating the queries, are there any tools you could recommend that could analyze query plans of those and suggest the kind of indexes that should be created? My current approach is ... wait until...

How can I persist a class to a single column using NHibernate

I'm looking to persist an object to a single column using NHibernate. I'd like to serialize the data on the way in into a single column, and then deserialize it on the way out. This could be binary or xml. How can I go about doing this? ...

Querying with NHibernate.

Hi, I am new to NHibernate and I am trying to learn how to query my data. Below is the configuration xml. Only the recipe is shown. I want to be able to query recipes by recipetitle from keywords entered and also ingredients from ingredientname. So you might enter "pasta wine" for example. This is what I have tried but gives me an e...