nhibernate

nhibernate insert question - have id but not entity object

Using NHibernate I need to insert an entity into a database that has a child entity. Example: public class Reservation { public int Id { get; set; } public Service Service { get; set; } } public class Service { public int Id { get; set; } } I need to create a new Reservation and insert it. However, when constructing the R...

Tricky Fluent Nhibernate modeling with subs of subclasses

I'm moving a project off of a custom DAL and onto Nhibernate but I've run into a tricky mapping scenario that I don't know how to resolve. Essentially, there are sub classes of a subclass without a discriminator value. The primary subclass has a discriminator value so that was trivial. The issue arises when I get to the third level. The...

NHibernate lazy loading. Retrieve data on demand.

I have some class with associated list. I want this list not to be loaded when I retrieve the entity, but I want to have an opportunity to load this list later, outside the session in which I cought the entity. Can NHibernate's lazy mechanism do this? Thanks! ...

Join to a Table using two non-FK columns with Fluent NHibernate

I'm using Fluent NHibernate and I have two tables: BusinessPlan [Id, Year, CustomerCode] PreviousYearData [Id, Year, CustomerCode, MoreFieldsForData] In my domain, I want to join PreviousYearData to the BusinessPlan to make entities something like this: public class BusinessPlan { public Guid Id { get; set; } public int Ye...

strategy for passing nhibernate entities between pages

I am working on a customer sign-up workflow. As expected, there are multiple steps that collect information. I need to store the results of each step until the workflow is complete. Once the workflow is completed then everything is written to the database. If the user leaves the workflow half-way through they will have to start over from...

Mapping one colun twice in fluent nhibernate

Here we go... I have a table (which unfortunatelly I can't change) with columns like: date, startTime, endTime. And I have data classes with two fields: startDateTime = date + startTime endDateTime = date + endTime Map(x => x.EndDateTime) .Columns.Clear() .Columns.Add("date", "endTime") .Custo...

NHibernate - KeyColumn from Parent Table

Hi, my application has the following database structure: Transactions: - TransactionID (PK, Identity) - Type - TotalAmount TransactionDetails: - TransactionDetailID (PK, Identity) - TransactionID (PK) - Amount ProductTransactions: - TransactionID (PK, FK) - Discount ProductTransactionDetails: - TransactionDetailID (PK, FK) - ProductI...

Nhibernat won't persist decimals in double correctly

When trying to persist a double with NHibernate in a MS Access database, i get the following problem. SQL reported by NHibernate: NHibernate: UPDATE mytable SET MyDoubleColumn = ? WHERE Number = ? AND Row = ?;@p0 = 5.8, @p4 = 161447, @p5 = 1 According to this, MyDoubleColumn should be set to '5.8', however, what gets stored in the dat...

NHibernate loading error message

I am having the error message with MappingNHibernateException: {"Could not compile the mapping document: Infrastructure.DataAccess.Mappings.Post.hbm.xml"} Could not find the dialect in the configuration on the part Configuration configuration = new Configuration() .AddAssembly("Infrastructure"); ...

example of best practice to refer to when getting started with NHibernate?

I would like to have a simple sample NH project that you would consider best practice that people could refer to when getting started with NH? I've been using it for a couple of months now and still struggle with the numerous ways there are to do things but not knowing which is the best approach to follow. ...

Fluent Nhibernate ClassMaps and Column Order

Our entities have a group of common properties. In order to reduce repetitive mapping, I created a base ClassMap that maps the identities and common properties. For each entity's ClassMap I just subclass the base and it works great. For a new project we are also letting NH generate the DB schema for us. The issue is, the order of the col...

How to do a JOIN between two tables using Castle ActiveRecord

I'm trying to perform a join in ActiveRecord using DetachedCriteria. I can't seem to make it work. There is no relationship defined inside the transfer objects. In SQL I should be able to do this but it seems that ActiveRecord wants to force me to define the relationship. What is the deal? Can someone point me to some documentation? ...

does nhibernate.burrow work with mvc.net and dot net 4.0 framework

I am thinking of using nHibernate.Burrow in my mvc.net application. However there are several troubling things that I have read and I am hoping to get them sorted out before I embark on the project: Are there any issues with running .Burrow with mvc.net? Are there issues with running .Burrow with the 4.0 framework? How tightly couple...

What is isWeb attribute for in Castle ActiveRecord

The official documentations says: If ActiveRecord is running in a ASP.Net application, you must add this attribute with the value true So naturally I turned it on and immediately noticed that those background threads (using Quartz.net) that use ActiveRecord to access the Database crash because they try to access HttpContext when th...

nHibernate Select statement for specific fields

I'm using nHibernate with c# to get a list of records or strings from the database as show in the first couple of lines of code below. This works fine. What I want to do is select a few specific fields from the record and not the entire record. I have tried various techniques and can't seem to find any examples on how to do this. Cou...

NHibernate Mapping Property Beyond LINQ Querying

Hi, my application has the following entity: public class User { public virtual int UserID { get; set; } public virtual Membership LatestMembership { get { return Membership.First(); } } public virtual IList<Membership> Membership { get; set; } public User() { Membership = new List<Membership>(); } } W...

Is there a way to delete all foreign entities when i delete a record using NHibernate?

I recently began using Fluent Nhibernate for my data layer and have come across an issue. Whenever i want to delete a record that has multiple foreign key constraints, i have to create another class just to represent that database entity. That means that for something like a User record, which has relationships with many other tables, ...

Does EF4 support mapping 1 component from several tables?

At my company we have a database with one table being so big that it was splitted into 3 tables. They all share an ID and the info is NOT normalized so there is info for several entities in the tables, some entities actually have some fields in one table and some fields in the other tables. There is a new project and they want to use nH...

Expression inside Projection Methods

How do I write the below with ICriteria and Projections.Sum: Select item_name, sum(unit_price * amount) from sales group by item_name Thanks ...

NHibernate 3 LINQ not assigning variables correctly

Hello, I'm attempting to use NHibernate 3.0.0 Alpha 2 and I'm running into issues with the LINQ provider. If I do a simple query such as var query = rep.AvailableProjects.Where(o => o.RequestorId == searchDto.RequestorId && o.ProcessCd == searchDto.ProcessCd); I get the following SQL as output: select table0_.REQUESTOR_ID as REQUEST...