nhibernate

Check if Database raises a particular exception

using Nhibernate; I'm trying to insert several values a on table which has an unique index on some columns. I'd like to know if a particular insert raises an exception for having violated the unique constraint. So, which particular exception type should i catch? I only want to catch this particular one and let all others go up. Thank...

From C# to hbm.xml

I'm looking for a NHibernate Mapping generator which could generate a mapping file (hbm) and SQL Script from a C# class. I've found generators for the other way around, but not for this case. Can you guys point me to nice generator? Thanks a lot! ...

Using a Generic Repository pattern with fluent nHibernate

I'm currently developing a medium sized application, which will access 2 or more SQL databases, on different sites etc... I am considering using something similar to this: http://mikehadlow.blogspot.com/2008/03/using-irepository-pattern-with-linq-to.html However, I want to use fluent nHibernate, in place of Linq-to-SQL (and of course n...

nHibernate session - Using repository pattern in Web, windows, wcf etc...

I recently posted a question which was answered by Bryan Watts, regarding generic repository for nHibernate. I'm trying to design my data access to allow various facets - from ASP.net, WCF and Windows Forms / Windows services. I'm a bit confused re: session management etc.. How would I handle this? I've been checking out code such a...

Nhibernate upgraded getting 'Antlr.Runtime.NoViableAltException' on outer join using *=

so we upgraded to newer Nhibernate and Fluent Nhibernate. now I' getting this exception: FailedNHibernate.Hql.Ast.ANTLR.QuerySyntaxException: Exception of type 'Antlr.Runtime.NoViableAltException' was thrown. near line 1, column 459 On this hql, which worked fine before the upgrade. SELECT s.StudId, s.StudLname, s.StudFname, s.StudM...

"Using a single session in multiple threads is likely a bug" error in NHProf when using NServiceBus

When executing an NServiceBus handler that uses NHibernate for its data access operations, I am seeing an error that I am not sure if I need to be concerned with. The handler has code that does something like this: using (var tx = Session.BeginTransaction()) { var accountGroup = _groupRepository.FindByID(message.GroupID); acc...

Nhibernate, can i improve my MAPPING or Query

take this simple example A staff class which references other instances of the staff class public class Staff { public Staff() { Team = new List<Staff>(); } public virtual int Id { get; set; } public virtual string Name { get; set; } public virtual IList<Staff> Team { get; set; } public virtual Staf...

NHibernate second-level caching of collections

I am having trouble working out how to correctly cache one-to-many or many-to-many relationships in NHibernate. For example, an office class may have the following mapping: public OfficeDbMap() { ... HasMany(x => x.Employees) .Cache.NonStrictReadWrite(); } However I find that when I delete an employee (without specifi...

NHibernate stored procedure problem

I'm having a hard time trying to get my stored procedure works with NHibernate. The data returned from the SP does not correspond to any database table. This is my mapping file: <?xml version="1.0" encoding="utf-8" ?> <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="DomainModel" namespace="DomainModel.Entities"> <sq...

Upper extension method in linq to NHibernate

I would like to use the Upper extension method which is declared on the IDbMethods interface against Sql Server 2008. The extension methods are defined in NHibernate.Linq.SqlClient.SqlClientExtensions I understand that this will translate to UPPER() on sql server. However I can not figure out how to get an implementation of IDbMethods...

Nhibernate FieldNameLookup throws IndexOutOfRangeException

Hello everyone Every now and then we get this very weird error NHibernate.ADOException: could not execute query [ SELECT this_.Id as Id37_0_, this_.AREA_ID as AREA2_37_0_, this_.BAT_CHK as BAT3_37_0_, this_.BAT_COD as BAT4_37_0_, this_.BBEACT as BBEACT37_0_, this_.CREDATE as CREDATE37_0_, this_.DEST_LOC as DEST7_37_0_, this_.DOCNR as DO...

How to map a Dictionary<string, string> spanning several tables

I have four tables: CREATE TABLE [Languages] ( [Id] INTEGER IDENTITY(1,1) NOT NULL, [Code] NVARCHAR(10) NOT NULL, PRIMARY KEY ([Id]), UNIQUE INDEX ([Code]) ); CREATE TABLE [Words] ( [Id] INTEGER IDENTITY(1,1) NOT NULL, PRIMARY KEY ([Id]) ); CREATE TABLE [WordTranslations] ( [Id] INTEGER IDENTITY(1,1) NOT NULL, [Value] ...

Using NHibernate to insert/update using a SQL server-side DEFAULT value

Several of our database tables contain LastModifiedDate columns. We would like these to stay synchronized based on a single time-source. Our best time-source, in this case, is the SQL Server itself since there is only one database server but multiple application servers which could potentially be off sync. I would like to be able to use...

How to have NHibernate persist a String.Empty property value as NULL

I have a fairly simple class that I want to save to SQL Server via NHibernate (w/ Fluent mappings). The class is made up mostly of optional string fields. My problem is I default the class fields to string.empty to avoid NullRefExceptions and when NHibernate saves the row to the database each column contains an empty string instead of...

how to force nhibernate to set the foreign key of the child item?

i have a collection in the mapping: <bag name="Values" cascade="all-delete-orphan" lazy="false" inverse="true"> <key column="[TemplateId]"/> <one-to-many class="MyNamespace.Value, MyLib"/> </bag> the Value object has a foreign key [TemplateId]. both entities has their generator set to "identity". when i call session.Save() for th...

NHibernate: Collection was modified; enumeration operation may not execute

Hi All, I'm currently struggling with this "Collection was modified; enumeration operation may not execute" issue. I have searched about this error message, and it's all related to the foreach statement. I do have the some foreach statements, but they are just simply representing the data. I did not using any remove or add inside the...

Override delete behaviour in NHibernate

Hi all In my application users cannot truly delete records. Rather, the record's Deleted field gets set to 1, which hides it from selects. I need to maintain this behaviour and I'm looking into whether NHibernate is appropriate for my app. Can I override NHibnernate's delete behaviour so that instead of issuing DELETE statements, it is...

Inheritance mapping with Fluent NHibernate

Below is an example of how I currently use automapping overrides to set up a my db representation of inheritance. It gets the job done functionality wise BUT by using some internal default values. For example, the discriminator column name winds up being the literal value 'discriminator' instead of "ActivityType, and the discriminator va...

Nhibernate + Gridview + TargetInvocationException

For our grid views, we're setting the data sources as a list of results from an Nhibernate query. We're using lazy loading, so the objects are actually proxied... most of the time. In some instances the list will consist of types of Student and Composition_Aop_Proxy_jklasjdkl31231, which implements the same members as the Student class...

NHibernate mapping with optimistic-lock="version" and dynamic-update="true" is generating invalid update statement

I have an entity "Group" with an assigned ID which is added to an aggregate in order to persist it. This causes an issue because NHibernate can't tell if it is new or existing. To remedy this issue, I changed the mapping to make the Group entity use optimistic locking on a sql timestamp version column. This caused a new issue. Group has ...