nhibernate

How to Handle a reference class with a unique field in NHibernate

I am using NHibernate and need to update/add an entity class(a) that can reference another entity class(b) that needs to have a unique "name" field. So would it be best to: query with NHibernate to find an existing entity(b) before the call to save entity(a). create stored proc to handle this update/insert logic. let table(b) uniq...

Nhibernate joined-subclass and orderby on base class

Hi Ive got a subclass, and I use this subclass on a bag, however I want to use the order by from the base class. But when I put the order by Nhibernate use the subclass. Does anyone know how to do this Ive put the mappings below. If I run that the sql does ordeby PersonDocument.Name, but it should be Document.Name Thanks... <bag nam...

Fluent NHibernate AutoMapping, supposed to save time but this has me pulling my hair out

I'm new to NHibernate and FNH as well. I'm familiar with ORM's and decided to see what all the buzz was about with this particular one mostly because of the productivity gains. At this point I think my time would have been better spent using something else but I don't want to let this defeat me and I'm hoping it's a stupid error I'm ma...

Nhibernate and sql scripts

Dont suppose anyone knows how to execute a sql script from nhibernate. Ive got some static data that I need in a database, that is contained, in a staticData.sql file. When I run my integration tests, I recreate the database with the schema export command, and I need to run this data in. I realise I can get it in using .net, but Id reall...

How to cascade Save with CompositeId in NHibernate?

I have a simple three table DB with many-to-many relation. A(id, Name) B(id, Name) AB(AId, BId) references A and B The corresponding classes: public class A { public virtual int Id { get; set; } public virtual string Name { get; set; } } public class B { public virtual int Id { get; set; } public virtual string Name ...

How to use NHibernate to query by unique-key values

I'd like to use Example.Create() to query just by the unique values of an instance. To do so I need to find out the value of the unique-key property that had been set inside the mapping file, like this: <property name="MyColumn"> <column name="MyColumn" unique-key="MyUniqueKeyGroup"/> </property> For better understanding - her...

Why can't it get the id of the child right away?

I've been struggling with this for 2 days now so i thought i would give it a shot here. my scenario looks like this. i got a Customer and CustomerPhone. Now i save the Customer and CustomerPhone at the same time but the CustomerPhone doesn't get Id right away. but if i do a redirect to a other site and get the Customer object there the ...

Fluent Nhibernate AutoMapping -- 2 foreign keys to same table?

Let say I'm doing a basic transaction system where I have the following objects. public class User { public virtual int Id{get; set;} } public class Transaction { public virtual int Id{get; set;} public virtual Item Item {get; set;} public virtual User Seller{get; set;} public virtual User Buyer{get; set;} } Notice how...

Map to a list of Enums?

Hi I need to map a class which has a list of Enums to a db table, using NHibernate here are the objects public class Driver : IIdentity { private IList<Licence> licences; /// <summary> /// The drivers licences /// </summary> public virtual IList<Licence> Licences { get { return this...

nHibernate Criteria query with missing mapping

Hi, I'm trying to do the following thing: ICriteria criteriaSelect = session .CreateCriteria(typeof(Employees)) .CreateCriteria("Orders") ; var test = criteriaSelect.List(); With: public class Orders{ public virtual int OrderID { get; private set;} } public c...

NHibernate one-to-many relationship lazy loading when already loaded

I have a tree where every node is a Resource class: public abstract class Resource { public virtual Guid Id { get; set; } public virtual Resource Parent { get; set; } public virtual IList<Resource> ChildResources { get; set; } } as you can see this class is abstract and there are many different derived cl...

memcached or lucene.net with nhibernate

Hi, Does anyone have used memcached as a level2 cache or lucene.net for searching with nhibernate ? Can you please share your advances on nhibernate caching & indexing/searching. And, is memcached (with enyim cilent on the same machine by appserver) the fastest l2cache solution with nhibernate ? Best Regards sirmak ...

What if building Nhibernate session factory fails?

Hi all, I'm currently creating a system which in some cases, if the database is not available, uses a MSMQ instead. E.g. if the application (in one of the cases it's a wcf web service) starts, and the database is not available, all incoming requests should be written to the MSMQ. When the database is available again, the requests should...

Do unidirectional associations lead to non-required foreign key fields through NHibernate

Update Added mappings below Question summary I have a database with many required foreign key fields and a code base with many unidirectional associations. I want to use NHibernate, but as far as I can tell, I either have to make the foreign key fields in the database NULLable (not a realistic option) or change the associations to bidir...

NHibernate proxy question

I have a quick question. If I have an interface from which my class derives, I can use that interface as a proxy for lazy loading. If I have an abstract class from which my class derives, can I use the abstract class as a proxy for lazy loading? Thx alot! ...

NHibernate not inserting parent into the db

When I save a new Report, NHibernate inserts the Report, ignores the Publication and tries to insert the UserPublication. However SQL then complains about violation of FK constraint. Its like NHibernate doesn't think the Publication is new even though the row doesn't exist in the db. Think of the entity relationship as: A Report can hav...

NHibernate.ISession.Flush() is taking a long time after a Delete()-Operation

In my application I would like to clear/empty a table (which is the only one) in my SQLite-DB. I am programming in C#. _session is of type NHibernate.ISession. Here is my code: string queryFmt = "FROM {0}"; string query = String.Format(queryFmt, typeName); _session.Delete(query); _session.Flush(); My example-DB consists of over 5000 e...

FluentNHibernate Session Management in ASP.NET

New to NHibernate(my disclaimer). I came across a similar and interesting article regarding MVC, however, I'm more curious as to what general best practices are for managing NHibernate sessions within a generic web application. I've come across the Burrow project, but I'm starting to realize there seems to be a few different directions ...

Has anyone every received a "Unhandled Expression Type: 1004" using Linq to NHibernate?

I have a linq query that is passed into NHibernate which Linq2NHibernate will parse and return me populated entities. string firstName = "Ryan"; Store store = _repository.Query<Store>().Where(x => x.Employees.Select(y => y.FirstName).Contains(firstName)).FirstOrDefault(); The troublesome part is x => x.Employees.Select(y => y.FirstNam...

how to add event listener via fluent nhibernate?

I want to add an event listener (IPreUpdateEventListener) to add NH but I can't seem to find an example when using a fluent configuration. I want to be able to add the listener when I create the session factory, e.g. when the following code is execute. _sessionFactory = Fluently.Configure() .Database(MsSqlConfigura...