nhibernate

How to create NHibernate Criteria for Map/Dictionary associations

Hi all, I have a Fluent NHibernate mapping like this. public PersonMap() { Table("PERSON"); Map(x => x.FirstName) .Not.Nullable(); Map(x => x.LastName) .Not.Nullable(); HasMany(x => x.Ids) .AsMap<string>("id_type") .Cascade.SaveUpdate(); } So I could do something like this. Person p = new Person(); p.Ids["id1"...

NHibernate.Spatial and Sql 2008 Geography type - How to configure

I am trying to use Nhibernate with the Sql 2008 Geography type and am having difficulty. I am using Fluent Nhibernate to configure which I am fairly new to so that may be the problem as well. First, the class I am trying to persist looks something like: public class LocationLog : FluentNHibernate.Data.Entity { public virtual new int...

NHibernate lazy loading property - what does build-time bytecode instrumentation mean ?

I've tried to lazy-load a property in my domain model, but lazy loading doesn't work. (It is always loaded). [Property(0, Column = "picture", Lazy=true)] public virtual System.Byte[] Picture { get { return picture; } set { picture = value; } } When reading the documentation here it says that it requires build-time byteco...

NHibernate: restore inner objects' events

Suppose I have public class Parent { private IList<Child> _children; public void AddChild(Child child) { _children.Add(child); child.OnSmthChanged += ParentSmthChangedHandler; } public void RemoveChild(Child child) { _children.Remove(child); child.OnSmthChanged -= ParentSmthChangedHandler; } ...

Nhibernate - Getting a list

I am trying to fetch a list from my database fulfilling a given criterion. The statement I am using is : var products = session .CreateCriteria(typeof(Product)) .Add(Restrictions.Eq("Category", category)) .List(); Where, product is my Domain object sess...

Force NHibernate to issue an update

I'm having a problem with an ASP.NET application that uses NHibernate with the session-per-request model. I'm storing an object in SessionState and updating some of its properties using AJAX postbacks. When the user clicks "save" I lock the object to the current ISession and update its properties from the form. The problem occurs if the ...

Why is NHibernate lazy loading bound to the session?

Using Castle ActiveRecord, I stumbled into a problem when lazy-loading. The following works (obviously) using (new SessionScope()) { User singleUser = User.FindFirst(...) UserGroup groups = singleUser.Groups; // Lazy-loading groups. } Since I need to modify the session filters in a certain context (using interceptors), I crea...

ORM (esp. NHibernate) performance for complex queries

Hi, My company is in the process of rewriting an existing application from scratch. This application, among other tasks, performs complex SQL queries against order and invoice data to produce sales reports. The queries are built dynamically depending on which criteria are selected by the user, so they can be pretty complex if many crite...

mapping of composite nested key

Hi, I am working with legacy database with nhibernate (but assume the solution will be very similar as in hibernate) and we have nested composite keys, what I mean is following, our keys have this structure (this is pseudo c# syntax): class PartnerKey { Public Int PartnerNr } Class TaxArtKey { Public String TaxArt } Class PartnerTaxAr...

Set up caching on entities and relationships in Fluent Nhibernate?

Do anyone have have an example how to set up and what entities to cache in fluent nhibernate. Both using fluent mapping and auto mapping? And the same for entity relationships, both one to many and many to many? ...

NHibernate Criteria for a non-linked table

We are adding an attribute(tags) to a system. The attribute table is just a relation table without any foreign keys. Is there a way to add to the criteria to generate a where clause for the attribute table on a parent table. <class name="Account" table="dbo.Account" lazy="true" > <id name="Id" column="`AccountId`"> <generato...

[C#] NHibernate- Prevent deletion on a particular entity (i.e. make read-only)

Hi all How can I prevent NHibernate from deleting a single entity of a specific class? A programmatic way I am using at the moment entails checking for the entity's unique field "Name". Here's the scenario: I have a person and a group. The group can have persons and other groups. If the group named "Admins" is attempted to be deleted, ...

Mapping nested components in Fluent NHibernate

Hi all, I have a 'User' Entity that contains an 'Address' Value Object. I have this mapping ok using FNH's Component concept. However, the Address VO also contains a Country which is another value object. I had assumed that this should be just nested as another component, but this doesn't seem to work. Can anyone tell me how I shoul...

Display a property of a many-to-one entity on a gridview

Hello! I have a database with two tables, ProductLine and Supplier. ProductLine contains the foreign key SupplierId, while Supplier has a field "Name". Table ProductLine: ProductLineId(PK), Name, SupplierId(FK) etc. Table Supplier: SupplierId(PK), Name etc. In my program I have two classes, ProductLine and Supplier, of which Pro...

FluentNHibernate mapping to a view

I have a many to many relationship between entities and there is a table view acting as a lookup table defining the relationship. I'm curious how to map to a view as opposed to a table within a database. ie, Table mapping: public SomeMap() { Id(...)//set Id and other mapped properties HasManyToMany(x => x.Items) .Table("S...

Nhibernate/Domain Objects generate test objects with random data from factory

We are doing some DDD at work and I am trying to find a good utility for generating Domain Objects with random data, or predefined data, and populating dependent objects. Example Usage: var user = DDDObjectFactory.CreateUser(); user.Name = "TestUser"; In our world, a user can not exist without a organization, so if there is no organi...

nHibernate Collections issue ( check your mapping file for property type mismatches)

I'm getting the following error: Unable to cast object of type 'NHibernate.Collection.Generic.PersistentGenericSet to type 'Iesi.Collections.Generic.SortedSet. Invalid mapping information specified for type [Type], check your mapping file for property type mismatches". Here's my set definition: <set name="ProcessTrackerDetails" lazy=...

Fluent NHibernate HasManyToMany only works on first load

This is a weird one for me. I have a simple domain with 2 entities Company and Carrier. They have a m:m relation via another table. I set up my Fluent mappings as so public partial class Carrier { public virtual int ID { get; set; } public virtual string Name { get; set; } public virtual IList<Company> Companie...

Id property not populated

I have an identity mapping like so: Id(x => x.GuidId).Column("GuidId") .GeneratedBy.GuidComb().UnsavedValue(Guid.Empty); When I retrieve an object from the database, the GuidId property of my object is Guid.Empty, not the actual Guid (the property in the class is of type System.Guid). However, all of the other properties in the o...

NHibernate - Publish issue with oracle database

Hi I am using oracle with NHibernate in silverlight application. Locally my application is working fine. but when i publish it, it gives me an error "Cound not load an entity". When i execute the query specified in exception directly into oracle it gets execute. I have published it and tested it on IIS 7, it is working fine. But prob...