nhibernate

How to map my class to get the db's records with a custom method?

I'm developing a website with ASP.NET MVC, NHibernate and Fluent NHibernate and want to know how can I customize my Map to get records using a custom Method. My entities: public class ImageGallery { public virtual int Id { get; set; } public virtual string Titulo { get; set; } public virtual IList<Image> Images { get; set; ...

How to tell the Session to throw the error query[NHibernate]?

I made a test class against the repository methods shown below: public void AddFile<TFileType>(TFileType FileToAdd) where TFileType : File { try { _session.Save(FileToAdd); _session.Flush(); } catch (Exception e) { if (e.InnerException.Message.Contains("Violation of UNIQUE KEY")) throw new Argum...

How do you map a composite id to a composite user type with Fluent NHibernate?

i'm working w/ a legacy database is set-up stupidly with an index composed of a char id column and two char columns which make up a date and time, respectively. I have created a ICompositeUserTypefor the date and time columns to map to a single .NET DateTime property on my entity, which works by itself when not part of the id. i need t...

Ensuring inserts after a call to a custom NHibernate IIdentifierGenerator

The setup Some of the "old old old" tables of our database use an exotic primary key generation scheme [1] and I'm trying to overlay this part of the database with NHibernate. This generation scheme is mostly hidden away in a stored procedure called, say, 'ShootMeInTheFace.GetNextSeededId'. I have written an IIdentifierGenerator that c...

NHibernate: bidirectional many-to-one problem

I have a bidirectional relationship in NHibernate: <class name="Child" table="Children"> <many-to-one name="Parent" column="ParentId" not-null="true" /> </class> <class name="Parent"> <set name="Children" lazy="true" table="Children" cascade="all"> <key column="ParentId" not-null="true" /> <one-to-many class="Child" /> </...

Is there Linq to Nhibernate for stateless session?

I was using regular session for loading some items from database via linq. The problem is that it caches the entities and memory load increases very much unnecessarily. Is there a way to replace session with stateless session without introducing many changes in client code? ...

Using ReadOnlyCollection preventing me from setting up a bi-directional many-to-many relationship

I'm using NHibernate to persist a many-to-many relation between Users and Networks. I've set up both the User and Network class as follows, exposing each's collections as ReadOnlyCollections to prevent direct access to the underlying lists. I'm trying to make sure that the only way a User can be added to a Network is by using its "JoinNe...

NHibernate, Databinding to DataGridView, Lazy Loading, and Session managment - need advice

My main application form (WinForms) has a DataGridView, that uses DataBinding and Fluent NHibernate to display data from a SQLite database. This form is open for the entire time the application is running. For performance reasons, I set the convention DefaultLazy.Always() for all DB access. So far, the only way I've found to make this...

Named query not known error trying to call a stored proc using Fluent NHibernate

I'm working on setting up NHibernate for a project and I have a few queries that, due to their complexity, we will be leaving as stored procedures. I'd like to be able to use NHibernate to call the sprocs, but have run into an error I can't figure out. Since I'm using Fluent NHibernate I'm using mixed mode mapping as recommended here. H...

Fluent NHibernate Map Enum as Lookup Table

I have the following (simplified) public enum Level { Bronze, Silver, Gold } public class Member { public virtual Level MembershipLevel { get; set; } } public class MemberMap : ClassMap<Member> { Map(x => x.MembershipLevel); } This creates a table with a column called MembershipLevel with the value as the Enum st...

FluentNHibernate Unit Of Work / Repository Design Pattern Questions

Hi all, I think I am at a impasse here. I have an application I built from scratch using FluentNHibernate (ORM) / SQLite (file db). I have decided to implement the Unit of Work and Repository Design pattern. I am at a point where I need to think about the end game, which will start as a WPF windows app (using MVVM) and eventually implem...

nHibernate, Automapping and Chained Abstract Classes

I'm having some trouble using nHibernate, automapping and a class structure using multiple chains of abstract classes It's something akin to this public abstract class AbstractClassA {} public abstract class AbstractClassB : AbstractClassA {} public class ClassA : AbstractClassB {} When I attempt to build these mappings, I receive ...

NHibernate: how to do lookup a specific date in Nhibernate

How I can lookup a specific date in Nhibernate? I'm currently using this to lookup one day's order. ICriteria criteria = SessionManager.CurrentSession.CreateCriteria(typeof(Order)) .Add(Expression.Between("DateCreated", date.Date.AddDays(-1), date.Date.AddDays(1))) .AddOrder(NHibernate.Criterion.Order.Desc("Ord...

Altering lazy-loaded object's private variables

I'm running into an issue with private setters when using NHibernate and lazy-loading. Let's say I have a class that looks like this: public class User { public virtual int Foo {get; private set;} public virtual IList<User> Friends {get; set;} public virtual void SetFirstFriendsFoo() { // This line works in a un...

NHibernate and mysql timestamp

I am trying to do versioning with NHibernate and everything works fine, however right after the insert NHibernate tries to pull the generated timestamp by executing the following query: SELECT profileloc_.Updated as Updated14_ FROM profile_locale profileloc_ WHERE profileloc_.id=?p0 and profileloc_.culture=?p1;?p0 = 16, ?p1 = 1033 Wh...

NHibernate, and odd "Session is Closed!" errors

Note: Now that I've typed this out, I have to apologize for the super long question, however, I think all the code and information presented here is in some way relevant. Okay, I'm getting odd "Session Is Closed" errors, at random points in my ASP.NET webforms application. Today, however, it's finally happening in the same place over ...

Does NHibernate SysCache work in a non-web app?

I know SysCache uses ASP caching under the hood, but since I'm not aware of the implementation of the ASP cache (and if it depends on anything IIS), I was wondering if SysCache would work in a non-web application (like a Windows Service)? Activating it and using NHprofiler seems to show it is not. ...

Lazy property loading in Nhibernate and Spring

I'm using NHibernate 2.1.2 and Spring 1.3 I have two Text columns (blobs) in one of my classes. I'm trying to use lazy="true" for the mapping of those properties but NHProfiler still shows the two columns being added to the SELECT statement when the main object is loaded. I'm using Spring.NHibernate session factory and have configured ...

Visual NHibernate from Slyce

I found this tool Visual NHibernate at http://www.slyce.com/, but a search on here has not brought anything up for what I would have thought would have been a very popular product, in concept anyway. Has anyone used this product? Any feedback on it? Thanks ...

Fluent NHibernate OptimisticLock.None() causes "The string 'none' is not a valid Boolean value."

I'm using the following mapping: public class LoadMap : IAutoMappingOverride<Load> { public void Override(AutoMapping<Load> mapping) { mapping.HasMany(x => x.Bids).OptimisticLock.None(); mapping.Version(x => x.Version); } } But when I try to create the session I get the following exception: [FormatException...