nhibernate

nHibernate - Iterate properties of a class to generically add parameters for stored procedure

I want to have a class that defines my parameter data for a stored procedure. It's going to be a very simple object: public class MyQueryData : SprocObjectBase { public int Value1 { get; set; } public string Value2 { get; set; } public bool Value3 { get; set; } ... } It will inherit from a base class with shared values, like...

Preventing Nhibernate from persisting a specific collection in a class.

Hello Everyone, I have a Sponsor object which has a collection that looks like this... public virtual IDictionary<SettingId, object> SettingValueDefaults { get; set; } These are actually being pulled as a subset of a larger table. I need to be able to read from these, and that is working correctly. However, I would like to be able...

C# mvc2 nhibernate problem

I've got the following mapping in my application. The mapping is generated, by a custom tool. Other mappings generated work ok, but this one is giving me a strange error which I don't understand. This is the mapping; <?xml version="1.0" encoding="utf-8"?> <!--Generated by NHibernate.Mapping.Attributes on 2010-10-29 08:39:48Z.--> <hiber...

Nhibernate LINQ - caching problems

Hello everybody I have the following code factory = new Configuration().Configure().BuildSessionFactory(); session = factory.OpenSession(); var query = session.Linq<Root>(); var data = query.ToList<Root>(); var data2 = query.ToList<Root>(); This one generate 2 SQL queries, so i understand that first level cache isn't working. Does LI...

Namespace for Restrictions.Eq in nHibernate

This sounds like such a dumb question but I've spent too long looking for the 'Restrictions' object when attempting something like this... Objects objs = NHibernateSession.CreateCriteria(typeof(Objects )) .Add(Restrictions.Eq("ObjectName", objName)) I'm using nHibernate 2.2 I believe and have added references nHibe...

Get ID for a lazy many-to-one object with NO db access

I wonder if this is possible with any Nhibernate version. I have a class A with a property of class B connected by a lazy many-to-one relation. I'd like to get A.B.Id without going to the database (I mean, without getting the whole B entity). Is this possible? Thanks! ...

Lazy loading returns equal records.

I have entities: public class Document : PersistentObjectBase { public virtual long? FolderId { get; set; } } <id name="Id" column="ID"> <generator class="identity" /> </id> <version column="VERSION" name="Version" type="Int64" unsaved-value="undefined" /> <property name="FolderId" column="FOLDER" /> ...

Have NHibernate fetch certain properties on each invoke

Normally, when you define a mapping for a certain property of a class, NHibernate saves the value in the property as soon as it has been fetched. Either it's fetched immediately when getting the object, or it's lazily loaded on the first invoke of the getter of the property, but once it has been loaded from the database it's fetched. Pl...

How do I express this LINQ query using the NHibernate ICriteria API?

My current project is using NHibernate 3.0b1 and the NHibernate.Linq.Query<T>() API. I'm pretty fluent in LINQ, but I have absolutely no experience with HQL or the ICriteria API. One of my queries isn't supported by the IQueryable API, so I presume I need to use one of the previous APIs -- but I have no idea where to start. I've tried s...

What ORMs are capable of building up an entity from tables belonging to several physical data sources?

I am checking if I can use Entity Framework or NHibernate to build a conceptual model where fields of some classes are mapped from different physical data sources. EF looks promising, at least on paper: this blog post mentions that "you can mix and match a number of different database vendors, application servers or protocols to design ...

nhibernate linq and let keyword

Is this possible to use let keyword with nhibernate linq? I wrote posts = from post in postsRepository.GetPosts(name) let commentsCount = (from c in NHUnitOfWork.CurrentSession.Linq<Comment>() where c.Post.ID == post.ID select c).Count() select new ... and in r...

How do I copy an object with NHibernate

I am using Nhibernate (I am a complete noob), and what I want to be able to do is copy an entity that is loaded from the database and save it with a new Id... has anyone run into this situation? Any help would be very appreciated. ...

Linq2Sql or Nhibernate for MVC.NET project

I am going to make a smaller website in MVC.NET, mostly to learn how to work with the MVC.NET framework. I can't decide if I should use NHibernate or Linq2Sql as my Data Access Layer. Linq2Sql would much easier and faster to setup, but it doesn't have the capabilities as NHibernate (2 layer caching etc.). So would it be wiser to use mor...

{"Could not create the driver from NHibernate.Driver.DB2Driver."} I am using C#.net

We are using Nhibernate to connect to DB2 database. From my C# application. We are able to connect using Odbc and OleDB driver but we need to connect using IBM DB2 driver (IBM.Data.DB2.dll). We are not able to connect using it. We are getting below error seems NHibernate is not able to create NHibernate.Driver.DB2Driver. {"Could not ...

Value Object Mapping DDD+ Nhibernate

Hello , I have already read other SO posts dealing with similar but none clarified what I wanted to do. I have MyProduct Entity and MyItem Entity. Product is made up of MyItem(s) .same like order order line scenario. MyProduct Will need to have value objects public class Item : EntityBase { public Item() { } publ...

How can I get a list of entities in NHibernate where the ParentId might refer to different tables

I'm new to NHibernate so I'm sure that I'm just missing something fundamental. I have an table called Issue that has a ParentId column. The ParentId can refer to different tables (i.e. - Project or Customer, etc.) How can I do that query in NHibernate so that I can show only the Issues that belong to Project. Here is what I've tried....

NHibernate: get all data from all DB tables

How can I iterate throw mapped entities and get all data from database? I dont know on first place what is mapped by NHibernate... Configuration configuration = SessionProvider.Configuration; var mappedClasses = configuration.ClassMappings; IRepository repository = new Repository(); foreach (var mappedClass in mappedClasses) { var...

how to filter result from many to many using nhibernate hql

I have many to many relation between Posts and Tags tables. Using HQL I want to get only a few fields from Posts table and names of the tags. So I wrote: select p.field1, p.field2, count(distinct p.field3), t.Name from Post p left join p.Tags t group by p.field1, p.field2, t.Name I want to have post data and list of its tags. Result ...

I get an error in my first (fluent) nhibernate query Initializing[type]-failed... no session or session was closed

I just started with NHibernate, created my mappings using fluent NHibernate as follows: public class CustomerMap : ClassMap<Customer> { public CustomerMap() { Id(x => x._id, "Id"); Map(x => x._KdNr, "KdNr"); Map(x => x._Name, "Name"); HasMany(x => x._Contact) .Table("Contacts") ...

S#arp Architecture and NHibernate database relations

I have been starting to follow the example on http://www.sharparchitecture.net on how to create a site using MVC.NET and NHibernate. I have gotten T4 to generate a object called Author for me, and validate it at the database. I would like to create an object e.g. Book, but I can't however find any information on how I can create a man...