fluent-nhibernate

How to store a non truncated varchar(max) string with NHibernate and Fluent NHibernate

My DB schema has a string as a varchar(max). I have read the other questions concerning setting Length to more than 4000 or 8000 so that it really generates a (n)varchar(max) in the mapping but when I use Length(10000) in my mapping class, the hbm file actually shows length="10000" and if I save an entity with more than 10000 chars, it i...

How can I model this object hierarchy in Fluent NHibernate without violating DDD principles?

I am trying to build a domain model that will allow me to manage Contracts. The Contract class is my aggregate root, and it has a single property right now, which is Reviewers. Reviewers, in the context of the Contract, each have a property to it's parent Contract, and a First Name, Last Name, and Login. The reason they have these pro...

Fluent NHibernate and MySQL cast syntax?

I have a table in MySQL which has a string column 'Id' of the form "Xnnnn" where nnnn is a number. I want to find the largest nnnn defined. So I have: var c = s.CreateCriteria(typeof(Item)) .AddOrder(Order.Desc( Projections.Cast( NHibernateUtil.Int32, Projections.SqlFunction("substring", NHibernateUtil.String, ...

NHibernate Auditing - PostInsert Not Working

Hi, my application has the following entities: public class User { public virtual int UserID { get; set; } public virtual string UserName { get; set; } public virtual IList<UserLog> Log { get; private set; } public User() { Log = new List<UserLog>(); } } public class UserLog { public virtual int Use...

Fluent NHiberante Test VerifyTheMappings

Given the following [Test] public void VerifyMappings() { new PersistenceSpecification<Address>(Session) .CheckProperty(x => x.AddressLine1, "190 House 12") .VerifyTheMappings(); } The following will attempt to do a read and write to the datbase, however it leaves the record, is it possi...

How to make NHibernate serialize a given property to a binary field?

Hi everyone, I have a simple ASP.NET MVC web application that uses NHibernate with FluentNHibernate's auto mapping feature for its data access. I have encountered a scenario in which I would like NHibernate to persist some classes as binary data. For example, I have something similar to this: public class User { ... // This f...

Retrieving the listbox values from a modelpopup partial view in asp.net mvc2 using fluent hibernate

i am having tow list boxes in a modalpopup window. In the first listbox i am storing all the availble products.the other list box will be initially empty. using couple of buttons i can pass listitems between the listboxes. my problem is when i assign some listitems to the second listbox. i cannot get them back go the controller as a part...

NHibernate multiple references to the same record from a single object

I'm using Fluent NHibernate and the setup I have is as follows: An Address object, which is a simple list of address fields. A Company object which has two references to address objects, MainAddress, InvoiceAddress. The problem I'm having is that on occasion both MainAddress and InvoiceAddress may refer to the same record in the Addre...

Fluent Nhibernate Mapping

I get the following error: NHibernate.TransientObjectException : object references an unsaved transient instance - save the transient instance before flushing I NOW know that is because of the way my mapping is set up IE something is not being saved down before the flush. I completely understand that. Now my question is given...

Fluent NHibernate upgrade from 1.0 to 1.1

I have recently moved from FNh 1.0 to 1.1 using Sharp Architecture I have an abstract class that provides the Name column and is overridden but my entities. This worked fine in Nhibernate 1.1 but now the new version of fluent tries to map the name column twice. Is there anyway to stop this happening? ...

NHibernate - Generate Domain from Database

I know its possible to generate the database tables from the domain model. But is there any way of doing things the other way. I have a totally awful database (worst I have ever seen). Its sharded (16 Shards!!), split across multiple postgres databases (all on the same server) with foreign key relations like urn:dbtable:guid. Its pro...

Mapping abstract base classes using Fluent NHibernate Automapper

I'm using Fluent NHibernate's automapper to map the following domain model (via AutoMap.AssemblyOf<Ticket>()), but it's throwing an exception when creating a SessionFactory. class Ticket { Owner TicketOwner { get; set; } Owner CreatedBy { get; set; } } abstract class Owner { ICollection<Ticket> OwnedTickets { get; set; } ...

Fluent NHibernate and XML columns

I'm building a new site from scratch and am considering using Fluent NHibernate for my ORM. I think it'll handle everything easily except, possibly, my XML columns. I've never built a site with NHibernate at all (though I've used Hibernate for Java) so consider me a n00b. Ideally I'd like the XML to be treated as an XElement as Linq-to-...

Mapping multi-value field to IList<> with FluentHibernate

Hi, I have following problem: We have multi-value fields in DB like ProductLineIdList which stores every allowed productLines separated by comma (for example "2,13,27,33"). I would like to map this field to IList (list with 4 entities). Is it possible to do that? Thx ...

Interceptor for instance created by Fluent NHibernate

How can I create and setup an interceptor for e.g. when accessing a property or method on an instance created by Fluent NHibernate? ...

Tricky Fluent Nhibernate modeling with subs of subclasses

I'm moving a project off of a custom DAL and onto Nhibernate but I've run into a tricky mapping scenario that I don't know how to resolve. Essentially, there are sub classes of a subclass without a discriminator value. The primary subclass has a discriminator value so that was trivial. The issue arises when I get to the third level. The...

Join to a Table using two non-FK columns with Fluent NHibernate

I'm using Fluent NHibernate and I have two tables: BusinessPlan [Id, Year, CustomerCode] PreviousYearData [Id, Year, CustomerCode, MoreFieldsForData] In my domain, I want to join PreviousYearData to the BusinessPlan to make entities something like this: public class BusinessPlan { public Guid Id { get; set; } public int Ye...

Fluent Nhibernate, how to handle a has many that really only has one?

Currently I have a table "ComponentAnalysis" and a table "HistoryOfUse" that I am trying to map in Fluent NHibernate. A component analysis should only have 1 history of use and a history of use should belong to 1 component analysis. This would suggest to me that the tables should be set up for a 1 to 1 mapping. But the designer of the D...

Mapping one colun twice in fluent nhibernate

Here we go... I have a table (which unfortunatelly I can't change) with columns like: date, startTime, endTime. And I have data classes with two fields: startDateTime = date + startTime endDateTime = date + endTime Map(x => x.EndDateTime) .Columns.Clear() .Columns.Add("date", "endTime") .Custo...

NHibernate - KeyColumn from Parent Table

Hi, my application has the following database structure: Transactions: - TransactionID (PK, Identity) - Type - TotalAmount TransactionDetails: - TransactionDetailID (PK, Identity) - TransactionID (PK) - Amount ProductTransactions: - TransactionID (PK, FK) - Discount ProductTransactionDetails: - TransactionDetailID (PK, FK) - ProductI...