nhibernate

[NHibernate] Why is a session.Clear() needed to reflect the changes in the db in the this example?

I have the following code: public class A { private ISessionFactory _sf; A(ISessionFactory sf) { _sf = sf; } public void SomeFunc() { using (var session = _sf.OpenSession()) using (var transaction = session.BeginTransaction()) { // query for a object // cha...

UnitOfWork in action

Hi, I want to present you my windows forms application scenario: I want to create an invoice, so I open new window with invoice details. Then I want to add new customer (to the database), that I want to use in my invoice. After entering all the information (including new customer info) I click Save to save my new document. The questio...

Nhibernate Linq Error on Single or Default

I'm pulling my hair out over here and I'm not sure what's causing it. I have the following LINQ query: return Session.Linq<CandidateAccountEntity>().SingleOrDefault(p => p.UserName.ToLower().Equals(userName.ToLower())); and its throwing the following error: Index was out of range. Must be non-negative and less than the size of...

NHibernate: Querying on collection of strings (collection was not an association)

Hello all. I have this class that I want to persist with NHibernate. It has one collection, an IList, aggregating strings, rather than class instances, called DestinationCountryCodes. public class RoutingRule { public virtual long Id { get; set; } public virtual MessageType MessageType { get; set; } public vi...

Is it possible to have a composite id that can be edited in NHibernate?

I have a situation where I have tables that have many columns used as a composite primary key, worse off business logic requires these to be mutable. I am using nhibernate and have no problems mapping for loadig/saving these. However I need to be able to update the property values and have these changes be reflected in the DB when i ...

Castle ActiveRecord Class Table Inheritance

I'm trying to create Class Table Inheritance as in ( http://www.castleproject.org/activerecord/documentation/trunk/usersguide/typehierarchy.html ) So let's say I have 2 classes: [ActiveRecord("entity"), JoinedBase] public class Entity : ActiveRecordBase { private int id; private string name; private string type; ...and propert...

Castle ActiveRecord HasAndBelongsToMany issue

Hey, I'm using monorail/activerecord and was wondering how you handle adding items in a many to many relationship when the many to many table has a value in it besides just the 2 foreign keys. For example, Business and Amenity classes have a many to many relationship so there is a BusinessAmenity table. If the BusinessAmenity table on...

NHibernate Generated values and Testing

I'm using NHibernate for data access. I'm working on writing some tests for my data access layer and have a scenario where I'm selecting records within a specific date range. In test, I generate test data by just selecting random dates within a range and then I try to select records with dates within a subset o that range. For instanc...

nhibernate - problem with merging collections

I have parent/child relationship, and child have composite id Parent <id name="Id" type="Int32"> <generator class="identity" /> </id> <set name="Children" table="CTable" cascade="all-delete-orphan" inverse="true" lazy="false" > <key column="ParentId"/> <one-to-many class="ChildrenClass"/> </set> Child <composite...

Is there a coherent way to use ICriteria and Linq to NHibernate in the same query?

It looks like this question: NHibernate.Linq and MultiCriteria provides a potential way to combine using Linq to NHibernate and ICriteria together in the same query (in my case, to add fulltext search predicates to Linq to NH queries). If you wrapped the Linq to NHibernate IQueryable<T> with your own implementation, you could even inc...

How much time NHibernate takes to close database connection as it is reaching Max connection pool size

Even after successful transaction.Application connection with the database persist How much time application takes to release database connection?????? Hi , I am using Spring.Data.NHibernate12 on my database level.my application connection with database is not getting released. Underneath given is Dataconfiguration.xml <?xml versio...

How to structure nhibernate class in separate project

I am working on my first NHibernate project, and have the following setup/requirement. I have 2 projects xx.Data, and xx.Business. In the Data project, this is where my domain classes, mapping files are located. What I am doing is creating an online application, whereby I have a SQL table that stores the ID, modified date, and an XML fi...

Checking the Intersection of Two Collections via HQL

I have an class which has a collection, mapped as a bag in my nHibernate mapping file for that class, and I wish to return all instances of that class whose collection has a one or more of the objects which I pass in. Example: My Parent Class is called DocumentDefinition. It has a collection of Roles, which is a nHibernate entity, that...

NHibernate. get singleOrDefault

I have the following method. This returns a single unqiue order. However i just want the first result. What is the best way to achieve this. Of course i could return a List and then get the first result from that. ie .List<Order>().SingleOrDefault(); Surely there is away through the criteria api to acheive this? Model.Order order...

Fluent nHibernate saving null id - leaves orphans

Hi, I'm witnessing some strange behaviour from Fluent nHibernate. I have two objects involved in this problem: a "Page" object and a "Metadata" object. A Page can have multiple Metadata objects attached, and the mapping is done thus: 'in PageMap HasMany(Function(x) x.MetaData).Cascade.All() 'in MetaDataMap References(Function(x) x.Page...

Lib to build an admin-page from a Database schema?

Hi all I'm using ASP.Net and NHibernate to build a website. Now, I need to add some sort of administration functionality, and came to think of an old django tutorial I once ran through. Here the admin page was build for me, and I could customize it as I liked. I see no reason that I couldn't accomplish the same, somehow, in ASP.Net, wh...

Issue with using ODP with NHibernate

Hello, I have .NET 3.5 application wrote in C# using NHibernate. Before I has OracleClientDriver in connection.driver_class property, that say that I use System.Data.Oracle and all works fine, but for some reasons now I need using ODP, so I changed this property to: NHibernate.Driver.OracleDataClientDriver. When I run my code I get follo...

CreateSqlQuery on entity with formula property

When I try to query a table using CreateSqlQuery and convert it to an entity containing formula property, I get the below Adoexception. "Value cannot be null. Parameter name: fieldName" In the first place is it possible to use the createsqlquery on entity that has formula mapping ? ...

Fluent Nhibernate - Specify foreign key constraint name between class and joined subclass

Hi, I think this should be simple, but I can't figure out how to do it. Suppose I have the following maps: public class AnimalMap : ClassMap<Animal> { Id( x => x.Id); } public class CatMap: SubclassMap<Cat> { Extends<AnimalMap>(); Map(x => x.IsDomestic); } Which creates tables as I expect: Animal ------ Id Cat ---- Animal...

Hibernate restrictions (And / Or)

Hi, small questions about Restrictions. i have query like this : Where A in(1,6) and (B not like 'Value%' or B not like 'ValueII%') the problem is the field B not contains a fixed value, can be one or more. Please, (N)Hibernate experts - help me with this, I cant find a working solution. Any help is greatly appreciated! ...