nhibernate

Getting Data from all tables instead of one with HQL Query that should only get 1 table's data

I have created 3 tables in my database and put data into them. The 3 tables all have foreign keys joining them together. Below are the table classes and there mappings. When I run the query listed at the end I get IList<> of the objects and they have the data from all 3 tables. However, my HQL query is only from the top most table. ...

Relating classes in NHibernate

I have a situation where I have a class that is referenced by several other classes. For example, my ContactInformation class is referenced by multiple different classes, such as Customer, Business, Location, etc. Since it is referenced by multiple classes, I am unsure of how to make a two-way mapping so I can insert a Customer with it...

NHibernate: getting multiple entities with subset of child collection?

Hello, My classes look something like this (I include only the relevant properties): public class Order { public virtual Customer Customer { get; set; } public virtual IEnumerable<OrderLine> OrderLines { get; set; } } public class OrderLine { public virtual string Product { get; set; } // Simplified } Now I What I want is...

Fluent nhibernate automap subclasses from different assemblies

What I need to do is automap subclasses of my abstract page class. I need to find them in a list of assemblies that I get a runtime (at the initialization stage). I don't have any reference to the assemblies from the assembly of my mappings. My page class looks something like this: public abstract class Page : EntityBase { public ...

Castle ActiveRecord: Save is throwing StaleStateException

Following this question, I tried to convert a sequence of try..Insert()..catch..Update() into a single call to Save(). I'm getting StaleStateException with "Unexpected row count: 0; expected: 1". What am I doing wrong? Here is the code that fails: var u = new User {SignupDate = DateTime.Now, Name="Foo", OpenId = "Bar"}; ActiveRecordMe...

NHibernate: best moment to store GUI changes

Hello, I am a little bit confused with NHibernate and Session. As I understood, I am supposed to use sessions "as quickly as possible", meaning that two different interactions get their own session. What do I do in case of UI interactions, I want to store in the DB. I have a simple example, where a treeview lists some items, and is bou...

NHibernate Does Not Popluate DB Record

I am new to NHibernate and have been working with some tutorials. I created an object (Project) and passed it to the Session.Save(obj) method. To test, I had default values in each DB field and the method returned the primary key but the fields were blank. I removed the default values from the DB and I get a SQL error "cannot insert NULL...

Need help w/ NFLuent Hibernate mappings

I've searched around for a solution as best I can, but it seems I'm at a loss somewhere. This is my first dive into Fluent NHibernate & NHibernate. The short version (which will still be long) is that I have a database that has tables User, Role, UserRoles. The relationship b/t them should be fairly intuitive...A user can be assigned mu...

Missing support for ambient transactions in nhibernate?

Ok, I know nhibernate supports ambient transactions, because nhibernate sessions enlists in the ambient transactions while inside a transaction scope. However, there are some oddities, consider the following test: [Test] public void Transaction_RollsBackTransactionInsideOfAmbientTransaction_AmbientTransactionAborted() { ...

using a temporary table with NHibernate

I'm trying to make what seems to be an advanced use of NHibernate with sql server functions. I'm using NHibernate's ICriteria interface to supply paging, sorting and filtering for my listviews. one of business objects is an aggregation of items from 3 different tables. in order to do this aggregation in the DB I've used a transact-sql fu...

Maintaining graph consistency in relationships with nHibernate

If I use bidirectional associations in nHibernate, is it necessary for me to add my own code to both sides of the relationship to automatically update the other side? For example, if I have a Many-to-One relationship between Book and Category public class Book{ public Category Category{ get; set; } } public class Category{ pub...

Where to handle StaleObjectStateException in asp.net mvc application?

Hi I'm using Session per Request pattern. Transactions are managed automatically. How can I easily handle StaleObjectStateException and show some specific view? ...

How do you save an Nhibernate entity with a joined field

I have a User table which has a foreign key to the UserType table. I created a User object with a Type property that is mapped as a join to the UserType table. Is there a way to insert a new User without inserting a new UserType? ...

Linq to sql VS Entity Framework VD NHibernate performance in an ASP.NET 3.5 Mashup style Application

I am tasked to build a web 2.0 style mashup application which consumes a lot of 3rd party webservices like youtube and twitter. There are also lots custom features which are going to be built using ASP.NET 3.5 and SQL Server 2008. Now I am looking for the right ORM for my needs. From a performance and ease of use standpoint can anyone su...

Actual dependencies of an entity

Is it possible to get a list of all related objects from a given entity, which I would like to delete? In the mapping I defined the cascading, that works well. But I would like to present the user which entities are currently connected to that entity so they might want to keep the entity. For example I have an entity event which has pa...

Properties Element in one-to-many mapping throwing exception

I am currently using version 2.1.2.4 of NHibernate. I am attempting to fetch a child collection of pages for a chapter on a non-PK column by using the element mapping configuration. I obtain a property not found exception for property "chapterToPages", which is really just grouping the 2 properties on the class to create the the propert...

nhibernate: Why is my entity not loaded into the first level cache?

I'm loading an instance twice from the same session, but nhibernate returns two instances which I am assuming means that the entity is not in the first level cache. What can cause this sort of behaviour? Test: using (new TransactionScope()) { // arrange NewSessionUnitOfWorkFactory factory = Creat...

NHibernate, WinForms, and DataBinding - do they play well together?

I've been using WinForms databinding to display data from a database mapped with Fluent NHibernate, and that's been working great. For example, I can just set a DataGridView's DataSource property from an entity's IList property, and voila - there's all the data! But now I need to start adding and saving new data rows, and that's not g...

How to map a collection of abstract classes in nhibernate

I have been reading Nhibernate in Action, but the section on mapping polymorphic collections is a little too short on how to do this. I have the following code [Class] [Discriminator(Column="MachineType",TypeType=typeof(string))] public abstract class Machine { [Property] public string Name{get;set;} } [Subclass(DiscriminatorValue...

is it possible to use linq with NHibernate just like with linq2sql or entity framework ?

I am using Fluent NHibernate and would like to use linq to query my database is this possible ? ...