nhibernate

Can I trust NHibernate Fluent Automappings?

I am currently testing using NHibernate Fluent Automappings to map my domain objects and create my database schema. Is this a good or bad idea? ...

Fluent Nhibernate Schema Generation

Hi, I have been playing about with FluentNhibernate as part of the S#arp Architecture. Below is an example mapping. public class EventBaseMap : ClassMap<EventBase> { public EventBaseMap() { WithTable("Event_Header"); //NotLazyLoaded(); Id(x => x.Id).WithUnsavedValue(-1).GeneratedBy.Native(); M...

Fetching only base type objects in nHibernate

Hello! I'm currently trying to solve a problem. I have a class table inheritance aka table-er-subclass (one main table + several others with additional data). In my app both base object instances and extended objects can exist. Now I want to be able to sometimes fetch only those base objects and sometimes both types. A simple example (b...

NHibernate won't persist DateTime SqlDateTime overflow

I am working on an ASP.NET MVC project with NHibernate as the backend and am having some trouble getting some dates to write back to my SQL Server database tables. These date fields are NOT nullable, so the many answers here about how to setup nullable datetimes have not helped. Basically when I try to save the entity which has a DateA...

NHibernate one-to-many mapping problem

I have to map two simple table with a foreign key relationship. One of the tables is Contact containing columns id (primary key of type int),name, address and guid (newly added and is not the primary key). The other one is phone__number containing columns id (primary key of type int), contact___id (foreign key of id in contact table) and...

How to map two tables with a foreign key relationship in NHibernate?

There are two tables, Contact and Phone__number. Phone_number contains a column contact_id which is a foreign key to id in Contact table. How do I map these two tables in Nhibernate so that I get List of PhoneNumbers in my contact class. ...

What is the best practice for readonly lists in NHibernate

Hello, Domain Model I am working on has root aggregate and child entities. Something like the following code: class Order { IList<OrderLine> Lines {get;set;} } class OrderLine { } Now I want my Order to control lines. Something like that: class Order { OrderLine[] Lines {get;} void AddLine(OrderLine line); } At this tim...

NHibernate with TransactionScope

Can anyone give me a quick overview of using TransactionScope with NHibernate? Do I need to do anything special with the session/IEnlistmentNotification/etc. to get this to work? Are there any pitfalls that I should worry about? For example, can I replace all of my hibernate transactions: var transaction = session.BeginTransaction(); tr...

Best way to implement add/edit functionallity in HTML for several classes at once

I'm writing a web application in C#. I have several classes which are stored in a DB with Fluent NHibernate. The users would be able to list, add, edit and delete these objects. I would like to avoid adding controls on a class-by-class basis for editing and adding the properties like Name or Text, but rather have some method to add/edi...

Multiple Levels of Children Entity Objects in Fluent NHibernate/NHibernate

Hi, I have a entity which has a list of Child1 objects. The mappings seem to work fine for this. If I try to add a list of Child2 objects to the Child1 entity and set up the mapping a xml mapping doesn't seem to get created and I get this error: Test method vRATest.ORMTest.NHibernateTests.NHibernate_Should_Be_Able_To_Get_All_Rout...

Linq to Nibernate design

I thought that the purpose of using Linq2Nibernate was to return IQueryable and build up an expression tree. I am not sure if this is correct or not. Why would anyone use Linq2Nibernate if they are not going to return IQueryable? What else would it be used for? I would love some more input on this topic Linq For Nhibernate ...

Best way to use NHibernate with the repository model

Hi guys, I have a repository class that defines some basic Get/Save/Delete methods. Inside these, I use NHibernate to do the work on my business entities. For example: Public Class SecurityRepositoryNHibImpl : Implements ISecurityRepository Public Function GetUser(ByVal UUID As System.Guid) As Entities.User Implements ISecurityRepos...

NHibernate with fluent mapping and Syscache2 second level caching

I have a very simple Country entity which I want to cache. This works perfectly, but I want a clone version of the cached instance to be returned or be made read-only to prevent developers from changing the state of it. How would I achieve this? I tought that the Fluent Readonly() method would enforce this, but it's not the case. Sa...

NHibernate - Saving parent when I have children IDs only

Let's say that I have classes like this: public class Parent { public int ParentId {get;set;} public IList<Child> Children {get;set;} public string Name {get;set;} } public class Child { public int ChildId {get;set;} } Someone calls a method to save a new Parent and passes me a name and a list of Child IDs, and I want to ...

Features - NHibernate versus Writing Custom Object-Relational Mapper

I'm looking for a list of all the features you would have implement in a custom object relational mapper (ORM) to meet all the features of NHibernate. to start: database portability through different drivers and dialects caching lazy loading custom SQL query interface - LINQ, Criteria, QBE (Query By Example) basi...

Letting the database pick the primary key in nhibernate

How do I just simply allow MySQL to assign a primary key to an inserted object with nhibernate? It seems I would want to set the generator as a type "identity", but the documentation states that using this "..require[s] two SQL queries to insert a new object." Why would it do that? Is there some way to get this functioning like a normal ...

nHibernate select query?

I have an ado.net statement I want to convert to use NHibernate: Dim sql As New StringBuilder() sql.AppendLine("SELECT r.RoleId, r.RoleName ") sql.AppendLine("FROM dbo.aspnet_Roles r ") sql.AppendLine("WHERE r.RoleId IN ") sql.AppendLine(" (select roleID from dbo.MenuRole where menuId = @MenuId) ") sql.AppendLine("Order By r.RoleName")...

Lazy Loading in NHibernate

If a Customer has many Orders attached to them. How would you lazy load the Orders List using NHibernate. Is it something that needs to be set up mapping file? any help or an example would be great. ...

nHibernate SetFirstResult & SetMaxResults Problems

I am using nHibernate and trying to implement some paging. If I run this code IList list = session.CreateQuery("FROM Author").List(); it returns 8 records. If I run this code though IList list = session.CreateQuery("FROM Author") .SetFirstResult(1).SetMaxResults(5).List(); it returns 0 records. When I look at the SQL generated ...

NHibernate Fluent Automapping Across DLLs

I have a Person class in 1 project/dll and a StandardUser class that derives from Person in another project/dll. I have a Password class that contains a StandardUser (Password and StandardUser are in the same dll). I can't seem to get the fluent automapping to work with this scenario. It tells me: NHibernate.MappingException: An as...