fluent-nhibernate

Automapping conventions for when Property and backing field have NOTHING in common?

Using Fluent NHibernate, I cannot seem to devise the necessary automapping conventions for the following (seemingly simple and common) use-case: public class MyClass { private int _specialIdentityField private string _firstname; public Id { get { return _specialIdentityField; }; } public virtual string Firstname { ...

Fluent NHibernate: Model Markov chain

I want to use Fluent NHibernate to model a Markov chain. It's basically a set of different states with transition probabilities between the states. I want to map the transition probabilities into MarkovState.TransitionProbabilities as a Dictionary. I want to use the NEXT state as key (using either MarkovState or int as key), so that I c...

fluent / nhibernate mapping question

Hey Guys I would very much appreciate some help with the following. We're using fluent to control the mappings for nhibernate and its all gone well so far. We've basically got a scheduled based CMS system and I'm having problems using the HasMany mapping to exclude the non-live child categories. So we have the following Data Tables, s...

Mapping a single class to columns in two tables with Fluent nHibernate

I have the following database tables: TABLE dbo.Client ( ClientId PK uniqueidentifier , ClientNames VARCHAR(200) ) TABLE dbo.User ( userID PK UniqueIdentifier, password varchar(15), passwordsalt varchar(15), ClientID FK uniqueidentifier ) I want to map them to my class: public class Client { public virtual Guid Id {...

fluent nhibernate: INSERT error when saving a new entity with a child entity

I am trying to save a new entity 'Post' with 1 item added to its 'Revisions' List. A 'Post' can has many PostRevisions, and a PostRevision can only have one Post I have tried several ways of mapping the PostRevisions, my PostRevisionMap is as follows: public PostRevisionMap() { Id(x => x.PostRevisionId, "PostRevisionId");...

Where clause in Fluent NHibernate Many-to-Many

I am trying to setup a many-to-many mapping in Fluent Nhibernate that has a where clause attached to the child table. This is basically how it should work: HasManyToMany(p => p.Images) .Table("ProductImages") .ParentKeyColumn("ProductID") .ChildKeyColumn("ImageID") .Where("ImageTypeID = 2"); The ImageTypeID column is in the I...

FluentNhibernate mapping one-to-one

Hi, I have inhertited an legacy application, that I have little control over. I need to map a one to one relationship because "A user may have one of these, lets call them 'a Rejection', but not more than one" The data stored in the Rejection table is quite large. Anyway, I have simplyfied this model, using cats, dogs and an owner. An ...

Fluent NHibernate: Cascade delete from one side only on Many-to-Many relationship

Hi All, I'm trying to write the proper map configuration that will allow me to delete from only one side on a Many-to-Many relationship setup. Below is the code structure for my Map and Entity class along with the actual program (psuedo) code and SQL schema. Fairly simple and straight forward. We have a person table, and a file table...

How can I create a parent/child relationship with the same object with AutoPersistenceModel

I have the following class in my project public class ProductCategory { public virtual Guid Id { get; set; } public virtual string UrlSlug { get; set; } public virtual string Title { get; set; } public virtual bool IsActive { get; set; } public virtual IList<Product> Products { get; set; } public virtual ProductCategory Par...

Fluent NHibernate get Id of saved object

I'm using Fluent NHibernate in an Asp.net MVC application. I have it set up to start a session and transaction on every request, and commit the transaction at the request end. However, what I want to do is save an object (in this case, a new "Company") and then redirect to that new Company's detail page. How do I get the Id of the new co...

Cascade Saves with Fluent NHibernate AutoMapping - Old Anwser Still Valid?

I want to do exactly what this question asks: http://stackoverflow.com/questions/586888/cascade-saves-with-fluent-nhibernate-automapping Using Fluent Nhibernate Mappings to turn on "cascade" globally once for all classes and relation types using one call rather than setting it for each mapping individually. The answer to the earlier q...

Fluent nhibernate mapping problem: many to many self join with additional data

I am struggling with mappings for the following sql tables |Post | |PostRelation | |------------------| |-----------------| |PostId |1--------*|ParentPostId | |---other stuff--- |1--------*|ChildPostId | | | |RelationType | Ideally Id l...

NHibernate: Join on multiple non key fields with property-ref

I have the following two tables in a legacy database Group --------- Id (PK) Code (char(4)) Year (int) Name nvarchar(100) Person ---------- Id (PK) Code (char(4)) Year (int) GroupCode (char(4)) And I want a class for Person that looks something like this class Person { public virtual int Id { get; set; } pub...

Fluent NHibernate Many-to-One Join on a Substring

I'm trying to map 2 tables together in Fluent Nhibernate, but the only way to join them is based on using the LEFT function on one of the columns. So a SQL join would look like this: select * from TableA INNER JOIN TableB ON LEFT(TableA.ColA, 12) = TableB.ColB Is there any way to map this in NHibernate? ...

Can't figure out what the other side of the many-to-many property 'Users' should be.

My Domain auto mapping was working but now as I updated my NHibernate stack I'm getting mapping exception when Session Factory is building the Configuration: "Can't figure out what the other side of the many-to-many property 'Users' should be." The exception is thrown on a many to many map The whole stack trace is this o...

Use Component as IDictionary index in AsMap in Fluent Nhibernate

I currently have the following property on an object: private IDictionary<ExampleKey,ExampleObject> example; where ExampleKey is public class ExampleKey { public long KeyField1{ get; set;} public long KeyField2{ get; set;} } This maps with hbm with the following syntax: <map name="example" inverse="true" cascade="all-dele...

NHibernate Property-ref linked property always lazy loads

I have a property in one of my models that is linked to a non-key field using property-ref. It always lazy loads even though explicitly set to not do so. I have other properties in the same class that reference other model objects using the normal method (on their key fields) and these take note of setting lazy load to false absolutely...

How to map IDictionary<string, Entity> in Fluent NHibernate

Possible Duplicate: Use Component as IDictionary index in AsMap in Fluent Nhibernate Hi, I have an class with an IDictionary on it. <map name="CodedExamples" table="tOwnedCodedExample"> <key> <column name="OwnerClassID"/> </key> <index type="string" column="ExampleCode"/> <many-to-many class="CodedExa...

join 3 icriteria with or

Is it possible to join 3 ICriteria together with OR statement not AND? ICriteria criteriaCity = NHibernateSession.CreateCriteria(typeof(Advertisements)) .CreateCriteria(AdvertisementsProperties.City.ToString(), "city"). Add(Restrictions.Or( Restrictions.Like("city." + CitiesProperties.Name.ToS...

Castle Project Active Record or Fluent NHibernate

We've been looking at using an ORM at work. Currently we are trying to way up the pro's and con's of fluent nhibernate against castle active record. We are unsure of the flexibility of each as our database isn't very conventional. It lacks foreign keys and identities on the primary keys (A little confusing but the next value is stored ...