nhibernate

NHibernate Joining on non-mapped property

Hi, I have two classes SystemInvitation and User. User has a property called Email and SystemInvitation has a property called InviteesEmailAddress. There is no relationship in the domain between these properties. Is it possible using the Criteria API to produce a query like: select si.InviteesEmailAddress , si.Identifier ...

Should I tell NHibernate/FNH to explicitly use a string data type for a param mapped to a string column?

A cohort of mine is building a somewhat long search query based on various input from the user. We've got NHibernate mapped up using Fluent NHibernate, and aside from some noob mistakes, all seems to be going well. One issue we can't resolve in the case of this search is that for a particular parameter, NHibernate is creating sql that ...

NHibernate persist System.Uri

I have a domain object that has a couple of Uri properties that need to be persisted to a Urls table that has several parts of the Uri from which the properties will need to be reassembled after retrieval. I can store the properties well enough, but how do I tell NHibernate how to recreate the Uri property? You can't set most of the Uri ...

How to test soft deletion event listner without setting up NHibernate Sessions

I have overridden the default NHibernate DefaultDeleteEventListener according to this source: http://nhforge.org/blogs/nhibernate/archive/2008/09/06/soft-deletes.aspx so I have protected override void DeleteEntity( IEventSource session, object entity, EntityEntry entityEntry, bool isCascadeDeleteEnable...

NHibernate mapping error - invalid child element 'many-to-one'

Using Fluent NHibernate with automapping, I am trying to map the following domain: public class Company: IModel { public virtual int Id { get; set; } public virtual string Name { get; set; } } public class Account: IModel { public virtual int Id { get; set; } public virtual string Name { get; set; } public virtual C...

NHibernate Get objects without proxy

I am using NHibernate(2.0.1.4) with NHibernate.Linq(1.0.0.4) to get Objects of the type Node from the Database. When I get these objects, the last object of the collection I got is of the type Proxy (because I used "NHibernate.ByteCode.LinFu"" ) I used the following linq query: var mynodes = from node in session.Linq<Node>() where ...

In NHibernate, is increment appropriate for identity key that's unique by group? What is appropriate?

I'm connecting to a legacy database that is our ERP system. I have a table that is using composite keys and one of those fields is incremented but it is unique within a subgroup of records. I have no ability to change this although I wish I could. For example, CustomerId_Field, SequenceID_Field 49, 1 49, 2 200, 1 200, 2 200, 3 200, 4 T...

Table per-subclass strategy when populating a large tree from a database using NHibernate

I am using NHibernate to load a large tree of objects of different types. Mapping is implemented using table-per-subclass strategy. I defined a base class "Node" that has only a few fields (NodeId, ParentId, NodeType) and several subclasses that inherit from Node and add their own fields. The implementation of this approach was straight...

Are NHibernate and XML Webservices (.asmx) a good match?

I'm looking at new architecture for my site and was wondering if pairing NHibernate with a web service core is a good idea. What I want to do is make my webservice the core of my business, from the site front ends to the utilties I write. I'm trying to make all of my UIs completely ignorant of anything but my service API's. In a simpl...

Has anyone built an nhibernate provider for Microsoft Index Server?

This may be an odd question! But I was wondering if anyone has ever attempted this. I guess the first question most people would ask is why!! With index server you can add additional meta data to standard file information (name, size etc). I want to be able to expose this information through to a BL component via nhibernate I need to ...

How to delete multiple db entities with Nhibernate?

What is the best practice for this problem? Is there any batching features built-in? Sample code: using (ITransaction transaction = _session.BeginTransaction()) { _session.Delete("FROM myObject o WHERE o.Id = IN(1,2,...99999)"); transaction.Commit(); } Thanks in advance. ...

How do I get random rows using nhibernate?

How do I select 5 random records using nhibernate. My sql looks like this: SELECT TOP 5 u.UserId, u.UserName, p.ImageFileName FROM users as u, profiles as p WHERE u.UserId = p.UserId ORDER BY NEWID() I tried doing this but it doesn't work IList<User> users = session .CreateCriteria(typeof(User)) ...

NHibernate property formula filter error

I am using NHibernate 2.1. I am trying to use a filter in a property formula, but am getting the following error: filter-def for filter named 'SiteFilter' was never used to filter classes nor collections. Here is my mapping file: <?xml version="1.0" encoding="utf-8" ?> <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="D...

NHibernate: How to Correctly Model This Schema

I have these related tables in my database: table [Files]: FileID FileName ------ -------- 1 /data/foo.jpeg 2 /data/bar.gif table [Attachments]: FileID DocumentID Caption ------ ---------- ------- 1 10 Foo is awesome. 1 20 Foo is horrible. 2 10 ...

NHibernate one-to-many relationship without bidirectional association

Is my understanding correct, that the following class and table design is not possible in NHibernate: public class Parent { public virtual Guid Id { get; set; } public virtual ISet<Child> Children { get; set; } ... } public class Child { public virtual Guid Id { get; set; } ... } table Parent { Id, ... } table Child { I...

please help me rewrite a simple sql into a NHibernate Criteria

I need to give to a Criteria a list of string receive another one, the sql that makes this is: select loginName from SimpleUsers where loginName in ('admin', 'oscar', 'stig') but I need it in NHinbernate criteria, can anyone please help me with this ? ...

NHibernate + join to derived table

In a table that stores multiple rows per employee, I want to pull one row per employee that represents the most recent entry for each employee. Here's where I am with hand-written SQL: SELECT [all the selected columns here] FROM Nominations t inner join (select max(NominationId) mostRecentNominationId, EmployeeId from Nomi...

NHibernate - is there a way to get more info from its exceptions?

I changed my enum to entity for design reasons, and got this exception from NHibernate: [MappingException: Could not determine type for: Orders.Core.Entity, Orders.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null, for columns: NHibernate.Mapping.Column(Entity)] I found the problem, it was that one of the classes d...

Persisting a valid Geometry shape into Sql Server 2008 Geography column

I am using Spatial.NHibernate to save some geometry shapes to a Geography column in Sql Server 2008. Here is my mapping: public class AreaMapping : ClassMap<Area> { public AreaMapping() { Id(c => c.Id).GeneratedBy.HiLo(100.ToString()); Map(c => c.Name).Not.Nullable(); Map(x => x.Boundary) .Cus...

Mapping an Array to a Single Row

I have the following classes: public class InventoryItem { private Usage[] usages = new Usage[12]; virtual public Usage[] Usages { get { return usages; }} virtual public string Name{get;set;} } public class Usage { virtual public double Quantity{get;set;} virtual public string SomethingElse{get;set;} ...