fluent-nhibernate

CreateAlias and NHibernate joins on classes w/ no mapped relationship

I'm beginning to wonder if I am in fact too dumb to use NHibernate. I'm currently using FluentNHibernate to create simple db mappings and that's worked well for us. When dealing w/ our various classes in isolation, we're able to read and write, perform updates, etc. to all of those classes. My problem however is in trying to build up ...

Mapping a JSON-encoded string in the DB to a Dictionary property on my object, using NHibernate

I have an object that maintains a property bag of various properties. This is exposed through my object model as a Dictionary<string, string> and is stored in the database as a JSON-encoded string. What is the best way to map this class using Fluent NHibernate? Option 1: Map to a private field, do JSON translation in my object? Shoul...

Using NHibernate to create an SQLite database with a "UNIQUE ON CONFLICT REPLACE" column.

Is this possible? If not, how can I create a table with a "UNIQUE ON CONFLICT REPLACE" column in code? ...

AssertionFailure: "null identifier" - FluentNH + SQLServerCE

The code fails at session.Save(employee); with AssertionFailure "null identifier". What am I doing wrong? using FluentNHibernate.Cfg; using FluentNHibernate.Cfg.Db; using FluentNHibernate.Mapping; using NHibernate; using NHibernate.Cfg; using NHibernate.Tool.hbm2ddl; namespace FNHTest { public class Employee { public vi...

Ensure NHibernate SessionFactory is only created once

I have written an NHibernateSessionFactory class which holds a static Nhibernate ISessionFactory. This is used to make sure we only have one session factory, and the first time OpenSession() is called I create the actuall SessionFactory - next times I use the same and open a session on it. The code looks like this: public class Nhibern...

Using ICompositeUserType on different tables with different column names.

Hi, I've been trying to get an NHibernate ICompositeUserType mapping to work. But am stuck trying to make the implementation generic enough to use on different tables. Our legacy database has many tables with latitudes and longitudes in and I want to map them into my domain objects as a Position class. The problem is each table has dif...

Problem with nhibernate linq Expand() statements results not being cached with rest of results

Hi All Some more cache related problems. I am having a problem getting the results of associated or child entities to be loaded into the nhibernate cache along with the root entity when using the Expand() method. So the following: var query = session.Linq<Promoter>(); query.Expand(x=>x.PromoterType); query.Query...

fluent NHibernate Reverse Foreign Key Lookup

Looking for a bit of mapping help. I am using the following so a parent can load a child. The child object 'ContactHistory' has no knowledge of it's parent. HasOne(x => x.ContactHistory).ForeignKey("ContactID"); However, I also need to do the reverse where the child loads its parent. I have tried the same mapping style and the code ...

Linq to NHibernate returns different results than HQL?

I have this basic entity setup: public class Instrument { public virtual int Id { get; set; } public virtual Guid? InstrumentGuid { get; set; } public virtual string FIPSCode { get; set; } public virtual IList Names {get; set;} } public class Name { public virtual int Id {get; set;} public virtual string Name {g...

NHibernate entity loose coupling

Let's say I have an entity called MyItem. It can be included in many "parents", like SomeCollection and SomeOtherCollection. Because it can be included in many parents, and since I don't want MyItem to know about the parents, I'd like to not have any properties in MyItem referencing a parent. And since a parent, like SomeCollection, can...

Generate identity from seed table in Fluent NHibernate

I need to generate an identity from a column in a seed table and increment the value in that column. e.g Seed Table: name "analysisid" id 1 Analysis Table: id name description On the analysis mapping I need to ensure that the id is taken from the seed table and on inserting an analysis the analysisid of the seedid is up...

Join tables with nested select count and group by in Nhibernate HQL

I have post, vote and comment table. Each post can have N votes and N comments. I have been trying to find a way to do this query using Nhibernate HQL with no success. SELECT P.Id, P.Title, P.TextDescription, ISNULL(V.TotalVotes,0), ISNULL(C.TotalComments, 0) FROM Post P LEFT JOIN (SELECT PostId, count(PostId) as TotalVotes...

Exception deleting child records in NHibernate

I have a simple parent/child tables. Contract is the parent table. Each contract can have multiple units. Here is my C# class definitions (simplified): public class Contract : EntityWithIntID { public virtual string ContractNum { get; set; } public virtual IList<Unit> Units { get; protected set; } public virtual int N...

HasOne vs References Mapping Fluent NHibernate

Hi, This is the first time I am working with FluentNhibernate Mapping and facing a question of how to reference another table. Any help is appreciated: I have several tables named CD_varname and all these contain two columns - CODE and DESCR. I have one main table called Recipient and it has, say two columns, called ALIVE and SEX, bot...

FluentNHibernate acts differently on different machines

I have run into an issues with FluentNHibernate that i hope someone can help me with. I have a many-to-many relationship between two classes named CampaignAreas and CampaignProducts. Sadly Fluent doesn't map the relation-table to the same table name on my machine as it does on my colleagues. It is named CampaignProductsToCampaignAreas a...

Fluent NHibernate and computed properties

I'm using Fluent NHibernate, and auto-mapping the classes. I have a computed property in a class along the lines of public virtual DateTime? LastActionTimeStamp { get { return Actions.Count == 0 null : Actions.OrderByDescending( a => a.TimeStamp).ElementAt(0).TimeStamp; } } This wasn't mapped with the rest...

Using NHibernate with lookup tables

If you have a set of tables in the database that strictly consist of a string description and an ID, what is the best way to load these via NHibernate? So suppose I have a Sandwich class, and a sandwich has a meat, a cheese, and a vegetable, where those three things are lookup tables in the DB. It seems to be the most conformant to NHi...

NHibernate Multiple Criteria Difficulties

Hi! I'm having difficulties with multiple joins in the NHibernate Criteria search. Say I had a pet table, and I wanted to return all pets where the pet category was Dog, and the owner gender was female, ordered by the pet birthday. I've tried a bunch of permutations for how I can get this but haven't been able to figure it out. My la...

fluent nhibernate one to many mapping

I am trying to figure out what I thought was just a simple one to many mapping using fluent Nhibernate. I hoping someone can point me to the right directory to achieve this one to many relations I have an articles table and a categories table Many Articles can only belong to one Category Now my Categores table has 4 Categories and Articl...

S#arp Architecture NHibernate instead of Fluent NHibernate

Is it possible to use NHibernate XML mapping files instead of Fluent NHibernate in S#arp Architecture framework? ...