nhibernate

Failed Castle ActiveRecord TransactionScope causes future queries to be invalid

I am trying to solve an issue when using a Castle ActiveRecord TransactionScope which is rolled back. After the rollback, I am unable to query the Dog table. The "Dog.FindFirst()" line fails with "Could not perform SlicedFindAll for Dog", because it cannot insert dogMissingName. using (new SessionScope()) { try { var trans = new T...

Approaches to use Repositories (w/ StructureMap) with AutoMapper?

Any idea how I can tell AutoMapper to resolve a TypeConverter constructor argument using StructureMap? ie. We have this: private class StringIdToContentProviderConverter : TypeConverter<string, ContentProvider> { private readonly IContentProviderRepository _repository; public StringIdToContentProviderConverter(ICon...

Why doesn't nHibernate support LIMIT when doing "join fetch"?

In nHibernate, if you do an HQL query with "join fetch" to eagerly load a child collection, nHibernate will ignore SetMaxResults and SetFirstResult and try to retrieve every single item from the database. Why? This behavior is specific to HQL, as ICriteria supports eager loading (with an outer join, though) and LIMIT. There are more de...

Dump iBatis sql in Nunit?

I saw nHibernate video during the weekend. In the tutorial, the programmer was using MBunit to test his code. One neat thing i liked about nhibernate was, if you tell nhibernate to 'showSql', it displays sql in Mbunit dialog box after the unit test. I was wondering if there is something similar for ibatis using nUnit? ...

Configure NHibernate with mapping assembly dll in other dir than config file

Hi First I will try to explain what I want to do. The app loads a NhHibernate config file and parse the xml, allowing changes to the connection string and the mapping assembly. The problem is that when I run the app in the directory that contains NHibernate.dll and all references, it works well, but if I run the app from other direc...

[N]Hibernate Sessions

A silly question, perhaps, but at this time of night, StackOverFlow is my only friend. I'm playing with NHibernate and wanted to factualize these 2 statements regarding Sessions in web applications. 1) You should only ever have 1 ISessionFactory per database for the lifecycle of an application. 2) You should only have 1 ISession per H...

nhibernate configure and buildsessionfactory time

I'm using Nhibernate as the OR/M tool for an asp.net application and the startup performance is really frustrating. Part of the problem is definitely me in my lack of understanding but I've tried a fair bit (understanding is definitely improving) and am still getting nowhere. Currently ANTS profiler has that the Configure() takes 13-18 ...

NHibernate & Cancelling Changes to Entities

Hi, This seems like it would be a common issue to be but I don't know the best way to solve it. I want to be able to send an Entity to a view, have changes be made to the entity in the view, but then cancel (remove) those changes if the user cancels out of the view. What is the proper way to do this. Here are two options I have but I...

how do you translate a space value in a database field to a null in .NET with Fluent NHibernate?

I am working with a legacy database that stores "blank" values as a single space. Is there a way with Fluent NHibernate, either by way of a convention or mapping override, that I can translate this "blank" value as a .NET null? (I know that I will need to save nulls to this database as a single space still but I will use an save event ...

NHibernate - Mapping tagging of entities

Hi! I've been wrecking my mind on how to get my tagging of entities to work. I'll get right into some database structuring: tblTag TagId - int32 - PK Name tblTagEntity TagId - PK EntityId - PK EntityType - string - PK tblImage ImageId - int32 - PK tblBlog BlogId - int32 - PK class Image Id EntityType { get ...

Are concurrency issues possible when using the WCF Service Behavior attribute set to ConcurrencyMode.Multiple and InstanceContextMode.PerCall?

We have a WCF service that makes a good deal of transactional NHibernate calls. Occasionally we were seeing SQL timeouts, even though the calls were updating different rows and the tables were set to row level locking. After digging into the logs, it looks like different threads were entering the same point in the code (our transaction...

Phantom updates due to decimal precision on calculated properties

This article describes my problem. I have several properties that are calculated. These are typed as decimal(9,2) in SQL Server and decimal in my C# classes. An example of the problem is: Object is loaded with a property value of 14.9 A calculation is performed and the property value is changed to 14.90393 When the session is flushed, ...

Modeling a Generic Relationship (expressed in C#) in a Database

This is most likely one for all you sexy DBAs out there: How would I effieciently model a relational database whereby I have a field in an "Event" table which defines a "SportType"? This "SportsType" field can hold a link to different sports tables E.g. "FootballEvent", "RubgyEvent", "CricketEvent" and "F1 Event". Each of these Sp...

Nhibernate database connection in MySql using Asp& C#

I'm trying to save the values in database. But here I can able to save only once after executing. During second time it shows inner exception as "{"Duplicate entry '' for key 1"}" ...

nHibernate persist IList<DayOfWeek>

Is it possible to persist an IList<DayOfWeek> using nHibernate? public class Vendor { public virtual IList<DayOfWeek> OrderDays { get; private set; } } If not, what are some common solutions; creating a class for OrderDays?, using an IList<string>? ...

NHibernate dateTime as an ID Bad idea?

hi there I have an entity and it seems like using DateTime as the Id would be a good suit, however I there is this strange feeling that that it might be a terrible idea ( tho i cant come up with any logical reason as to why), This is an immutable object ( ie once the value is recorded it shouldn't really change ) So DateTime as id fie...

Nhibernate Linq In Clause

Is it possible to get Nhibernate linq to generate a query with an "In" clause? e.g. - Where AnID in (x,y,z)? ...

How to design a data model that deals with (real) contracts?

I was looking for some advice on designing a data model for contract administration. The general life cycle of a contract is thus: Contract is created and in a "draft" state. It is viewable internally and changes may be made. Contract goes out to vendor, status is set to "pending" Contract is rejected by vendor. At this state, nothing ...

Nhibernate transactions:Avoiding Nhibernate dependency in the service layer

One of practices advocated by Nhibernate experts is to do all actions in inside a transaction. In a typical 3 tier web architecture, Nhibernate depedency is limited the data layer. In such a case is it fine to use using (var tr = NHibernateSession.Current.BeginTransaction()) { at the controller level. Won’t this bring in a de...

Fluent Nhibernate ManyToMany collection - not saving associations

I can't get my head around why this isn't working.. I have a relatively clean entity model consisting of POCOs created with DDD in mind (while probably not following most rules even loosely). I am using Fluent NHibernate to do the mapping. I am also using SchemaExport to create the database schema, with minimum input from me on how to ...