nhibernate

Fetch child without primary key NHibernate

I am trying to get a collection of objects into a parent object through mapping. I have a parent object "ScoreCard" whose primary key is a guid (Id) and a child "Score" object whose primary key is a guid (Id). I want to select the child objects for the parent based on two fields that both objects have but I can't get it to work, here's ...

Mapping Error in NHibernate

Hi, I am trying to use NHibernate to connect to a Northwind database. But for some reason, I am not able to load the Entity Type. This is my Entity class public class Product { public virtual Int32 ProductId { get; set; } public virtual String Desc { get; set; } } Here is my Mapping <class name="Product...

NHibernate Saving 0 to many-to-one column instead of null

I have a table Donations which has a CampaignID column that relates to the Campaigns Table. I need to insert a 0 in the CampaignID column instead of Null if the Campaign is not used for this Donation. My mappings from the Donations table looks like this: <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" auto-import="true"> <cla...

Fluent NHibernate HasMany not updating the FK

I'm using latest Fluent NHibernate lib (0.1.0.452) and I have a problem with saving child entitites. I think this is rather common scenario... I've got a parent with mapping: HasMany<Packet>(x => x.Packets) .Cascade.All() .KeyColumnNames.Add("OrderId"); and a simple Packet class that (in a domain model and FNH...

NHibernate and sql timestamp columns as version

Hi, I've been racking my head trying to get Nhibernate to work with a byte array as version mapping to an sql timestamp. I'd implemented an IUserVersionType but Nhibernate was creating varbinary in the database rather than timestamp. Inspired by a blog post by Ayende recently on concurrency, I changed my mapping to specify the sql-type t...

NHibernate save error w/i database

I am calling Save on an NHibernate object that has many children attached to it. Upon save, sometimes an error happens when NHibernate starts inserting into my sql database ("The data was truncated while converting from one data type to another." for instance). Following are the top lines of an example Exception. NHibernate never tell...

How to debug nHibernate/RhinoMocks TypeInitializer exception

Pulling my hair out trying to debug this one. Earlier this morning, this code was working fine, and I can't see what I've changed to break it. Now, whenever I try to open an nHibernate session, I'm getting the following error: Test method BCMS.Tests.Repositories.BlogBlogRepositoryTests.can_get_recent_blog_posts threw exception: Syste...

NHibernate: exclusive locking

In NHibernate, I want to retrieve an instance, and put an exclusive lock on the record that represents the retrieved entity on the database. Right now, I have this code: With.Transaction (session, IsolationLevel.Serializable, delegate { ICriteria crit = session.CreateCriteria (typeof (TarificationProfile)); crit.SetLockMode (L...

Criteria representation of join query

There is two classes 1 class A[properties:-aid,aname] 2 class B[properties:-bid,A,bname] DropDownList ddlist; ICriteria criteria = ActiveRecordMediator<B>.GetSessionFactoryHolder() .CreateSession(typeof(B)).CreateCriteria(typeof(B)) .setFetchMode(“A”,FetchMode.JOIN); ddlistToLet.DataSource ...

NHibernate and Life Cycle Events

Can someone give an example to what Ayende is talking about in item #17 on his list of 25 Reasons Not To Write Your Own Object Relational Mapper Is this something that ADO.NET Entity Framework can do? ...

nHibernate Null List Values on One-To-Many

I have an Order mapping with many OrderItems. The mapping correctly saves both the Order and OrderItems to the database when I do a save on just the Order, but when I reload that order, the List of OrderItems that the order contains is filled with null values (for all the othe order items in the table) until it reaches the OrderItem tha...

NHibernate ASP.NET and Encrypted Connection strings Error

I get an error: Format of the initialization string does not conform to specification starting at index 0 in teh nhibernate config section of the web.config I have this set to use the named connection string: MyConnectionString And when I try it I get an error, now this worked fine with unencrypted connection string, I thought it would...

How to prevent insert of duplicate data with nHibernate?

I'm building a blog/CMS system (for fun, I know there are a ton out there I could use). I have a simple Tag entity that only has an Id (int) and a TagName (string) property. I'd like to configure nHibernate such that I can do something like: var tag1 = Tag.CreateTag("duplicate tag test"); // Id=0 at this point var tag2 = Tag.CreateTag...

nhibernate Composite Foregin key

People, I have a horrible legacy DB that i have to map in nHibernate, that im not allowed to change. There is a horrible tree structure called FaultCodes with these fields: ID int eventID int treeID int (unique per eventID) parentTreeID int ID is the PK, its used by other tables to join to this one. Problem is, the parent/child r...

Problem with sorted <map> when a value is null

Hi, I'm trying to persist a SortedList<DateTime, double?> with NHibernate 2.0. When an item's value (not key) is null, that item is not persisted to the database. Class snippet: public class TimeSeries{ ... public TimeSeries(){ Data = new SortedList(); } public virtual IDictionary Data { get; private set; } ...

NHibernate Flush-- How it works?

Hello, I am kind of confused on how Flush ( and NHibernate.ISession) in NHibernate works. From my code, it seems that when I saved an object by using ISession.Save(entity), the object can be saved directly to the database. However, when I update and object using ISession.SaveOrUpdate(entity) or ISession.Update(entity), the object in...

studying nhibernate critieria queries

Is there any other site for studying critieria queries like http://www.hibernate.org/hib_docs/nhibernate/1.2/reference/en/html/querycriteria.html ...

Batch Update in NHibernate

Does batch update command exist in NHibernate? As far as I am aware it doesn't. So what's the best way to handle this situation? I would like to do the following: Fetch a list of objects ( let's call them a list of users, List<User> ) from the database Change the properties of those objects, ( Users.Foreach(User=>User.Country="Antartic...

Nhibernate Criteria API

SELECT O.*, P.* FROM ORDERS O, PRODUCT P WHERE O.ORDER_ID=P.ORDER_ID; What would be the Criteria representation of the above query? ...

Find the Top 10 results from a table using Castle ActiveRecord

Hi, I'm trying to get say the top 10 scores for the users of my application. I'm usually using something along the lines of User.SlicedFindAll(0, 10, NHibernate.Expression.Expression.Eq("IsActive", true), NHibernate.Expression.Order.Desc("Score") which is usually used for pagination purposes. However, I don't want to add any const...