nhibernate

Delete from <Map>

I have mapping: <class name="User" table="Users" lazy="false"> <id name="id" type="Int32" column="id"> <generator class="identity" /> </id> <property name="name" column="name" type="String"/> <map name="Urls" table="UserUrl" lazy="true" inverse="true" cascade="all"> <key column="user_id"></key> <index column="url_t...

Partially Populate Child Collection with NHibernate

hi all, been struggling with this for a while, and cant seam to figure it out... i've got a BlogPost class, which has a collection of Comments, and each of the comments has a DatePosted field. what i need to do is query for a BlogPost and return it with a partially loaded Comments collection, say all comments posted on the 1 Aug 2009. ...

How To - Simple Nhibernate Join

how do i do this simple join either with hbm or fluently so i have a class like this? public class Pet { public Pet() {} public virtual int PetId { get; set; } public virtual int PetTypeId { get; set; } public virtual string Name { get; set; } } CREATE TABLE [dbo].[test_PetTypes]( [PetTypeId] [int] IDENTITY(1,1) NO...

How do I serialize an NHibernate DetachedCriteria object?

I am looking for a solution to persist NHibernate DetachedCriteria objects to a database. I have tracked down the NHibernateUtil and the GetSerializable method, but I'm unsure how to use it to serialize a DetachedCriteria object. Any help on this would be greatly appreciated. Thank you. ...

Mapping a derived class with additional collection property in nhibernate

I'm trying to use the table-per-subclass (which fluent-nhibernate automaps by default) with a class structure like the following: public class Product { public virtual int Id{ get; set; } public virtual string Title{ get; set; } } public class ProductPackage : Product { public ProductPackage(){ Includes = new List<Product>...

Fluent Nhibernate WrongClassException with Polymorphic Parent

Hello, I have been using joinedsubclass inheritence mapping for a while and decided to switch to table-per-class because it allows more efficient subtype descrimination. However on making the change I now get the below exception. Object with id: 1 was not of the specified subclass: MyModel.FooBase (Discriminator was: '2') Abridged cl...

NHibernate remove item in collection not working

I'm a newbie in the NHibernate world. Why this code works removing the territory from the collection: Country country; using (IUnitOfWork unit = UnitOfWork.Start()) { country = new Country(); country.Name = "My country"; Territory territory = new Territory(); country.Territories.Add(territory); country.Territories...

NHibernate config problem

Hi guyz, I feel so stupid for posting this but I can't see what's wrong here. I wanted to see hot Nhibernate works, than I got in the site, downloaded it, and was following the quick start tutorial but doing some chances - I'm using MySql and it's not a Product but a User in my project, but whatever... When I run the test for schema ge...

How to handle a few dozen flags in a database

Like most apps, mine has a "users" table that describes the entities that can log in to it. It has info like their alias, their email address, their salted password hashes, and all the usual candidates. However, as my app has grown, I've needed more and more special case "flags" that I've generally just stuck in the users table. Stuff...

Persist a top-level collection?

NHibernate allows me to query a database and get an IList of objects in return. Suppose I get a list of a couple of dozen objects and modify a half-dozen or so. Does NHibernate have a way to persist changes to the collection, or do I have to persist each object as I change it? Here's an example. Suppose I run the following code: var hq...

How do I configure FluentNHibernate to not overwrite an existing SQLite db file?

Here is my configuration: this.factory = Fluently.Configure(). Database(SQLiteConfiguration.Standard.UsingFile("foo.db"). ShowSql()). Mappings(m => m.FluentMappings.AddFromAssemblyOf<Bar>()). ExposeConfiguration(BuildSchema). BuildSessionFactory(); BuildSchema looks like this: private static void BuildSchema(C...

How to add new object to an IList mapped as a one-to-many with NHibernate?

My model contains a class Section which has an ordered list of Statics that are part of this section. Leaving all the other properties out, the implementation of the model looks like this: public class Section { public virtual int Id { get; private set; } public virtual IList<Static> Statics { get; private set; } } public class...

Adding new entity in NHibernate PostUpdateEvent

Hi, How do I add a new entity object using NHibernate whilst handling a PostUpdateEvent event? I have implemented an audit handler which essentially creates a new object in the OnPostUpdate handler, and attempts to insert into the database. However, it doesn't actually seem to get committed at any point. If I start a new transaction an...

Does linq and nhibernate return the same type of collection?

Hi, If I design my db layer so I can swap it between a linq-to-sql or nhibernate implementation, I have to code against an interface. This means the return type between both linq and nhibernate have to be the same i.e. List etc. Is the list type the same? ...

Why NHibernate simple select in HQL to SQLite database is not working ?

I've recently started using FluenNHibernate and some weird problem appeared when I tried to write unit test with SQLite. I use SQLite in memory database for test, for each test method I am clearing data existing in database. In example: var u = new User() { Name = "Piotr" }; _session.Save(u); _session.Clear(); var list = _session.Creat...

The repository pattern - looking up a repository based on a type

The application i am currently working on makes heavy use of the repository pattern with NHibernate. We have a generic base repository class that implements standard gets and saves. This class is then inherited by repositories for each type. These repositories can then add their own type specific methods (and override saves and gets if n...

NHibernate - Equivalent of CountDistinct projection using LINQ

I'm in the midst of trying to replace a the Criteria queries I'm using for a multi-field search page with LINQ queries using the new LINQ provider. However, I'm running into a problem getting record counts so that I can implement paging. I'm trying to achieve a result equivalent to that produced by a CountDistinct projection from the ...

Get executed SQL from nHibernate

I am using nHibernate ICriteria to execute a query, and I would like to be able to get the SQL that was executed after the statement runs. So for example I have something like this. ISession session = NHibernateSessionManager.Instance.GetSession(); DetachedCriteria query = BuildCriteria(); // Goes away and constructs the ICriteria var r...

Does NHibernate intergrate well with Microsoft Sync Framework?

We are wanting to use both NHibernate and Microsoft Sync Framework - has anyone had experience combining these two frameworks? Thanks, Ashley ...

nhibernate alternates batch size

When performing a query with NHibernate does not seem to be respecting the batch-size if it is set to more than the results actually returned. I am using the latest version of NHibernate 2.1.0.4000 and the GA of Linq to NHibernate. I have an object structure similar to the Order which has a collection of OrderLines. The OrderLines hav...