nhibernate

Unit of work/repository managers for NHibernate?

I'm a .NET developer by day, but have been working with Rails and Merb for the past year on my own side projects, so when it comes to MVC and ORMs, I'm more used to them and using ActiveRecord and DataMapper. I'm getting started with ASP.NET MVC, and I like what I see in NHibernate and Fluent NHibernate, but looking for a little bit mor...

Limit Result in NHibernate

How to limit the number of rows returned in NHibernate? I am looking for something like SetMaxResult(), but couldn't find it in Nhibernate namespace! Note: I want to use NHibernate.Criterion, not NHibernate.IQuery, so it's best if you can provide that example. ...

Using LINQ Expression Instead of NHIbernate.Criterion

If I were to select some rows based on certain criteria I can use ICriterion object in NHibernate.Criterion, such as this: public List<T> GetByCriteria() { SimpleExpression newJobCriterion = NHibernate.Criterion.Expression.Eq("LkpStatu", statusObject); ICriteria criteria = Session.GetISession().CreateCriteria(typeof(T)).SetM...

NHibernate mapping a reference table

I have a rather convoluted scenario/design to sort out and would much appreciate some advice or insight. I am trying to map the following with not much success. <class name="CalEvent" table="tb_calEvents" lazy="false" > <id name="id" column="id"> <generator class="hilo"/> </id> <property name="summary"/> ---snip---- <bag name="cat...

How to Insert into NHibernate DB after NHibernate Session

Let's say if I encounter an error in NHibernate db update, and when such an exception is thrown, I want to log it in the log table in the db, via NHibernate again. Now, since I can't reuse NHibernate session after an exception thrown, I will get an error when I log into the log table. How to best handle this situation? ...

How to store a lucene index so that it is accessible by more than one app server.

We have a single database that drives a number of applications. Each application uses the same database and the same NHibernate Mappings. I have recently implemented Nhibernate.Search in one of our applications. With a view to adding it to the others over time. If this happens I could potentially have a number of app servers updating on...

Getting NHibernate.Mappings.Attributes to work Options

I'm using v2.1 of NHibernate.dll and NHibernate.Mappings.Attributes v2.1 in a project. When I run the code further below, I get the following exception, and will be grateful for any pointers. On the same project, if I remove the attributes and use xml mapping files, it works fine. NHibernate.MappingException was unhandled Message="C...

In NHibernate how would I map an object to only retrieve it's children but ignore them when creating or updating?

How would one map this object to only retrieve the collection below and ignore it totally when creating or updating the object to the db? <bag name="children" table="tb_parent_child" lazy="false"> <key column="parentID"/> <one-to-many class="Child"/> </bag> thanks ...

CSLA.Net V3.6/NHibernate V2.10 ; how to overcome need for vitual properties

With CSLA.net, all domain classes need to inherit from Businessbase, which contains non-virtual properties. When using NHibernate, we need to implement virtual properties for lazy loading. Some options to use CSLA/NHibernate together seem to be: switch lazy loading off in NHibernate and implement lazy loading code in the domain cl...

NHibernate collections and moving objects

Hi, I just ran into a major issue for me with NHibernate. I have 2 objects, each with a collection of things. I need to move one thing from the collection from Object A to the collection of Object B. I get an error about a deleted object because, I believe, NHibernate attempts to delete the thing from the collection of Object A when it ...

Serialize DetachedCriteria with nHibernate

I am trying to serialize a DetachedCriteria so I can save it in a database and reuse the same criteria at a later date. When I run the code below I get "NHibernate.Criterion.DetachedCriteria cannot be serialized because it does not have a parameterless constructor". DetachedCriteria criteria1 = DetachedCriteria.For<SecurityObjectDTO>("...

using hql in NHibernate

I have two tables: -- Table: medibv.btdbn -- DROP TABLE medibv.btdbn; CREATE TABLE medibv.btdbn ( mabn varchar(8) NOT NULL, hoten text, ngaysinh timestamp, namsinh varchar(4), phai numeric(1) DEFAULT 0, mann varchar(2), madantoc varchar(2), sonha varchar(15), thon text, cholam text, matt varchar(3), maqu varcha...

how to user year() and month() functions in NH Criteria API?

I need to use year() and month() functions in Criteria API to be able to express a business filter constrain. Expressions like cri.Add(Expression.Ge("year(Duration.DateFrom)", Year.Value)); cri.Add(Expression.Le("year(Duration.DateTo)", Year.Value)); obviously do not work - is there any solution how to achieve this? I know it's enti...

Globalization with NHibernate

How would you build your domain objects and create its respective NHibernate mapping files for a multi language application. The UI part is stored in resource files but user data needs to go into the database. I want to do the following: Product p = DALProduct.getByID(2) p.name //results in the language of the current UICulture I hav...

What's the proper way to update an nhibernate entity from a asp.net POST action method?

I'm new to nHibernate, and trying to get my head around the proper way to update detached objects from a web application form POST. (We're using ASP.NET MVC) The object I'm trying to update contains (among other things) an IList of child objects, mapped something like this: We have arranged our MVC edit view form so t...

Does an ORM integrate with existing applications or do I not understand?

Assume Hibernate for the ORM. I'm not sure how to ask this. I want to build an application that can replace part of another. For example, say I have an application with various modules, called the "big" app. This application may handle HR, financial, purchases, skill sets, etc. But maybe, for whatever reason, I don't like the skill ...

using hql in NHibernate

hi every one i have 2 table btdbn and benhandt and i created 2 classes Btdbn and Benhandt CREATE TABLE medibv.btdbn ( mabn varchar(8) NOT NULL, hoten text, ngaysinh timestamp, namsinh varchar(4), phai numeric(1) DEFAULT 0, mann varchar(2), madantoc varchar(2), sonha varchar(15), thon text, cholam text, matt varcha...

NHibernate Projection to DTO

Hello, I am unfamiliar with NHibernate projection. I am attempting to use it so I can return a List<> rather that an IList<>. I am not having much luck with projecting to the DTO as of yet. I have the following query and Domain objects. So to begin I am just trying to get a list of Orders given an EmployeeID. I am looping through the re...

NHibernate Linq and DistinctRootEntity

When I execute the following query, I get an exception telling me that 'feedItemQuery' contains multiple items (so SingleOrDefault doesn't work). This is expected behaviour when using the Criteria api WITHOUT the DistinctRootEntity transformer, but when using linq, I expect to get a single root entity (FeedItem, with the property Ads (of...

Fluent Nhibernate composed entity, specify foreign key

I have a Fluent Nhibernate map like : public class UserMap : ClassMap<PortalUser> { public UserMap() { WithTable("aspnet_Users"); Id(x => x.Id, "UserId") .GeneratedBy.Guid(); Map(x => x.Name, "UserName"); Map(x => x.Login, "LoweredUserName"); WithTable("LdapUsers", m => m.Map(...