nhibernate

What is the difference between NHibernate and iBATIS.NET?

I am looking for some up to date information comparing NHibernate and iBATIS.NET. I found some information searching Google, but a good bit of it applies either to the Java versions of these products or is dated. Some specific things I am interested in: Which is better if you control both the data model and the application? iBATIS is...

NHibernate - Only retrieve specific columns when using Critera queries?

I'm propositioning NHibernate for a project we're doing at my company and I'd like to know if NHibernate can be optimized to only retrieve specific columns on a table when using the Criteria query language. For example. Let's say I have a table with 30 columns on it and this is mapped to an object using NHibernate that is a 1-for-1 matc...

nHibernate, No row with the given identifier exists

I have a mapping along the lines of this. <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" namespace="Model.Entities" schema="etl" assembly="Model" default-lazy="false"> <class name="Model.Entities.DataField, Model" table="mdm_field"> <id name="FieldId" column="field_id" type="int"> <generator class="native" /> </id...

Recommended Castle Windsor/NHibernate stack?

I've got a personal (learning) project that uses Castle Windsor (with the NHibernate facility) and NHibernate (and ASP.NET MVC and Moq, and SQL Server 2008, all stuff that I want to learn more about). I attempted to use NHibernate Validator over the weekend, but it needed the 2.1.0Alpha2 build of NHibernate. Since Castle Windsor 1.0RC3...

Wrap Transaction Inside Using-- Need to Close it manually?

I have the following code in accessing a database via nhibernate: ISessionFactory factory = new NHibernate.Cfg.Configuration().Configure().BuildSessionFactory(); using (ISession session = factory.OpenSession()) { ICriteria sc = session.CreateCriteria(typeof(Site)); siteList =...

Is LinqToSQL the same as Linq?

I was just reading about Linq to SQL being discontinued. For a while I put off learning Linq at all. Even on asp.net, when I last checked, their data access tutorials were using table adapters and bll classes. Then there are linq tutorials. Now that I have read this and that the Entity Framework is the new way to go, does that mean a...

How do i map this in NHibernate

I Have two classes, Survey and Poll classes. Also I have Question and Question Choice classes. How do I map these so I come out with particular table formats. here is the classes involved. public class Survey { public IList<Question> Questions { get; private set; } } public class Poll { public Question Question { get; set; ...

NHibernate: Map same class to multiple tables depending on parent

I have a model where multiple classes have a list of value types: class Foo { public List<ValType> Vals; } class Bar { public List<ValType> Vals; } Foo and Bar are unrelated apart from that they both contain these vals. The rules for adding, removing, etc. the ValTypes are different for each class. I'd like to keep this design in my c...

NHibernate Error reporting advice

Hi, This is not so much a problem as advice on best practice really. I am writing an ASP.Net MVC application, and in my DAL i am using NHibernate, but what do you do if an exception is thrown in your DAL? Do you catch the exception in the DAL, log the error and then re-throw the exception? Do you not even attempt to catch exeptions at ...

NHIbernate and Security / Business Layer

I'm just starting to play around with / learn NHibernate for a personal project, and feel like I'm not "getting" something. I'm used to having apps work like this: Presentation layer --> Business Layer --> Persistence layer. So for example, my presentation layer would call BusinessLayer.GetCustomer(id). In that method I would check that...

NHibernate unexpected ORDER BY Statement

Hi, I am using NHibernate 2.0, and when I submit a request asking for the top 2 records to be returned, I get a number of ORDER BY clauses in my SQL. When I take out the Max results, the query looks fine (no ORDER BY statements). Why is NHibernate automatically adding this when I am looking for a subset of records? Thanks in advance ...

adding an nHibernate mapping at run time?

Background: I'm getting a mapping failure when trying to use nHibernate. The application consists of several assemblies. One of the assemblies is a library of useful routines and the other is application code that uses the library. The library assembly adds itself to the nHibernate configuration but since it doesn't know about other ass...

Testing the persistence layer in a DDD/TDD application

If I have the following domain object: public class Customer { public virtual Guid Id { get; set; } public virtual string Name { get; set; } public virtual ISet<Order> Orders { get; set; } public Customer() { Orders = new HashedSet<Order>(); } public virtual void AddOrder(Order order) { ...

NHibernate Criteria Type Mismatch

This code ICriteria crit = service.Session.CreateCriteria(typeof (DatabaseVersion)); crit.Add(Restrictions.Eq("Id.Minor", 4)); IList<DatabaseVersion> list = crit.List<DatabaseVersion>(); causes the following error :NHibernate.QueryException: Type mismatch in NHibernate.Criterion.SimpleExpression: Id.Minor expected type System.Int16, a...

How to best design the entity data classes for the following SQL Schema?

I have the following database schema: The issue is how to create the entity data class in Nhibernate? Is this better: public class Store { public virtual int Id { get; private set; } public virtual string Name { get; set; } public virtual IList<Product> Products { get; set; } public virtual IList<Employee> Staff { ge...

NHibernate Table Update Event

I have this table mapping (details don't really matter I think): WithTable("COPACKER_FACILITY"); Id(x => x.FacilityNumber, "FACILITY_NUM").GeneratedBy.Sequence("FACSEQ"); Map(x => x.FacilityName, "FACILITY_NAME").Not.Nullable().Trimmed(); Map(x => x.AddressLine1, "ADDR1").Not.Nullable().Trimmed(); ... WithTable("FACIL_OTH_AUDIT_INFO",...

Forcing nHibernate to cascade delete before inserts

I have a parent object which has a one to many relationship with an ISet of child objects. The child objects have a unique constraint (PageNum and ContentID - the foreign key to the parent). <set name="Pages" inverse="true" cascade="all-delete-orphan" access="field.camelcase-underscore"> <key column="ContentId" /> <one-to-many c...

Fluent NHibernate - How to map the foreign key column as a property

I am sure this is a straightforward question but consider the following: I have a reference between company and sector as follows: public class Company { public Guid ID { get; set; } public Sector Sector { get; set; } public Guid SectorID { get; set; } } public class Sector { public Guid ID { get; set; } public stri...

Is Code Generation a Bad Thing?

This is a subjective question. Recently I have been trying to learn NHibernate. The problem with it is at least 2 fold: mapping xml file that needs to be coded by hand Entity Class that needs manual coding While NHibernate is a wonderful framework, but the need to write mapping file and to create entity classes that mimic the databa...

NHibernate 2 + Fluent Nhibernate medium trust

Will NHibernate 2 and\or Fluent Nhibernate work in a medium trust environment. If not are there any work-arounds? ...