nhibernate

S#harp architecture mapping many to many and ado.net data services: A single resource was expected for the result, but multiple resources were found.

Hi, I'm developing an application that reads data from a SQL server database (migrated from a legacy DB) with nHibernate and s#arp architecture through ADO.NET Data services. I'm trying to map a many-to-many relationship. I have a Error class: public class Error { public virtual int ERROR_ID { get; set; } public virtual string E...

nhibernate many-to-many with relationship specific properties

Is there a way to map a many-to-many relationship with properties on each item in the list specific to the relationship? The actual case I'm trying to solve is this: A business can be related to many contacts, and a contact can be related to many businesses. What I want to do is provide a status for the relationship, like active or d...

NHibernate Caching Objects Based on Parent Class's ID

I have the following definitions for the Animal and Dog types. Note that the ID for the object is the AnimalID: <class name="Animal" table="Animals"> <id name="Id" type="System.Int32" column="AnimalID"> <generator class="identity" /> </id> <property name="IsBig" column="IsBig" type="System.Bool" not-null="true" /> ...

NHibernate: Same class for multiple tables

Hi all, I have a file attachment class (FileAttachment) which is used in several other classes. e.g. An article contains multiple attachments. A category contains multiple attachments. These attachments are actually the same FileAttachment class but for obvious reason they are persisted in different tables. e.g. file attachment for an ...

NHibernate session.flush() fails but makes changes

We have a SQL Server database table that consists of user id, some numeric value, e.g. balance, and a version column. We have multiple threads updating this table's value column in parallel, each in its own transaction and session (we're using a session-per-thread model). Since we want all logical transaction to occur, each thread does ...

SQL server version column updates more than it should

We're using NHibernate to update an account table with balance for a user. One test case that stymies us is this: var s = NHibernateHelper.OpenSession(); var q = s.CreateQuery("Update Account set Balance=? where UserId=? and Version=?"); var acc = s.Load(1); ITransaction tx = null; for (int j = 0; j < NUM_UPDATES; j++) { int rowcou...

NHibernate: Lazyload single property

Hi, I have currently moved my blogengine over from Linq2Sql to NHIbernate. I'm stuck at the following performance problem: I got one table: 'Posts', that has Id, Title, PostContent, DateCreated collumns and so on. The problem is that, when I'm creating the "Recent posts list", I don't want the whole PostContent. In Linq2Sql you can s...

NHibernate - Deleting objects with composite PK, when one of the PK columns is NULL

Hey, i'm trying to delete an entity of the following structure from an Oracle 10g tables: class Record { string id; string name; DateTime dateTime; } with the following mapping: <class name="Records" table="RECS"> <composite-id> <key-property name="P_ID" /> <key-property name="NAME" /> </id> <property n...

hydrate in nhibernate?

what is hydrate in nhibernate? I am not able to get my head around this term. This was used, in a video, in context of hydrating the child table rows. Please advise. Thanks AJ ...

managing classes when everything is relative to a user in nhibernate (orm)

Firstly I have three entities. Users, Roles, Items A user can have multiple Roles. An item gets assigned to one or more roles. Therefore a user will have access to a distinct set of items. Now there is a few ways I can see this working. There is a Collection on Users which has Roles via a many-to-many assoc. Then each Role in thi...

Fluent NHibernate: How to tell it not to map a base class

I have been googling and stackoverflowing for the last two hours and couldn't find an answer for my question: I'm using ASP.NET MVC and NHibernate and all I'm trying to do is to manually map my entities without mapping its base class. I'm using the following convention: public class Car : EntityBase { public virtual User User { get...

Soft delete in cascade in NHibernate

I try to make a soft delete by implementing the DeleteEvent Listener public class MyDeleteEventListener : DefaultDeleteEventListener { protected override void DeleteEntity(IEventSource session, object entity, EntityEntry entityEntry, bool isCascadeDeleteEnabled, IEntityPersister persister, ISet transientEntities) { ...

Avoiding NULL object in HQL Query where clause

I have an entity which might have a parent entity. I want to run this query: select entity where entity.parent.id = 9 some of the entity does not have parents (entity.parent = null) and N HIBERNATE Fails to run this query (QueryException - Could not resolve property) How can I use HQL to get all the entities that has parents entities ...

Problem with Nhibernate saving a LongBlob in MySQL

When I want to save a longblob in mysql via nhibernate the app hangs. when nhibernate is going to save the object to the database, shows the sql, but when I going to see it on the console it writes the sql until the app hangs. Any ideas? Regards ...

nhibernate sql-query results different from direct query results

UPDATE: I've answered my question below, take a peek and let me know if you have a better way of doing this executive summary: when calling my sqlserver function from SQL Management Studio I get a list with results {1, 2, 3}. when calling the method from a code using NHibernate I get this list {1, 1, 1}. ('1' is an entire result row, ...

NHibernate: Should I encode inputs?

I use NHibernate to persist my objects.. However, I cannot seem to find any information about whether I need to encode inputs? For example: string firstName = TextboxFirstName.Text; string lastName = TextboxLastName.Text; using(ISession session = sessionFactory.OpenSession()) { Customer customer = new Customer(firstName, lastName)...

persisting byte[] to image db Field

hi there, I just switched to Nhibernate2.1.0.4000 with Nfluent 1.0RTM and Linq To Nhibernate 1.0.0. since then while Calling Save some entity containing an byte[] array which is mapped to an image database field, it takes ages to finish under debugging in the VS2008 debugger. public class Appendix { ... public virtual byte[] appendix...

get the next id

Hi all, My question is how to get the next id using NHibernate in a mysql db for an auto-increment ID column ? Thanks, ...

NHibernate: how to retrieve an entity that "has" all entities with a certain predicate in Criteria

I have an Article with a Set of Category. How can I query, using the criteria interface, for all Articles that contain all Categories with a certain Id? This is not an "in", I need exclusively those who have all necessary categories - and others. Partial matches should not come in there. Currently my code is failing with this desperate...

Use two joined subclasses in nhibernate

Ok, new to nhibernate and I am working on a project that has already fully implemented it. Scenerio: One class (Person) has two joined subclasses (RoleA and RoleB). What I need is that a given person can actually be both in RoleA and RoleB. How, when given a person that is already created and in RoleA, can I then make them also in R...