nhibernate-mapping

S#arp Architecture NHibernate instead of Fluent NHibernate

Is it possible to use NHibernate XML mapping files instead of Fluent NHibernate in S#arp Architecture framework? ...

NHibernate Override<> for many-to-any

I have a question for a specific many-to-any mapping problem: I'd like to have a fluent mapping for this simplified domain (non relevant properties removed) public interface IModule { Container Container { get; } } //This is mapped to [dbo].Container table in the database public class Container: Entity { // ... // I need to...

(fluent) nhibernate conditional table mapping strategy

I have no control over database schema and have the following (simplified) table structure: CityProfile Id Name CountryProfile Id Name RegionProfile Id Name I have a .Net enum and class encapsulating the lot: public enum Scope { Region, Country, City } public class Profile { public Scope Scope { get; set; } public int...

Nhibernate relationship table mappings

I am using NHibernate to persist information in my media player app. Basically at the minute I have a mapping setup for the Track class and for the Playlist class: Track Playlist ====== ========= Id Id Name Name FilePath etc... This is working fine...

How to map a property with formula in NHibernate?

I have a class which I want to add a property with using formula attribute. Here is the mapping that I use in mapping file. <property name="CurrentUserVote" type="Climate.Domain.Vote, Climate.Domain" formula="(select v from Vote v where v.AchievementId=Id and (v.IP=:CurrentUserVoteFilter.CurrentUserIP))"></property> As you see, I wa...

nhibernate mapping does not save/insert keys of inserted subclasses

After having changed around my mappings a bit ( see my other question about cascade-delete for reasons) , i tried inserting a completely new object and all its subclasses. After this another problem emerged, an issue with the insertion of the keys into the database. Situation is as follows: I have an object with 2 tiers of subclasses, ...

Is it possible to disable a filter which is defined for a property in nhibernate?

I have a filter defined for a property in a mapping file like this; <?xml version="1.0" encoding="utf-8" ?> <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" default-lazy="false"> <class name="Climate.Domain.CompanyAchievement, Climate.Domain" discriminator-value="0" table="CompanyAchievement"> <id name="Id" column="Id" unsave...

NHibernate: Violated not-null constraint when saving HasMany relation with Cascade=AllDeleteOrphan

Hi, My bean looks like this: public class A { ... [HasMany (MapType = typeof(B), Table = "B_table", ColumnKey = "A_object_id", Fetch = FetchEnum.Join, RelationType = RelationType.List, Index = "id", Cascade = ManyRelationCascadeEnum.AllDeleteOrphan)] IList<B> BList { get; ...

NHibernate: How to map same column to be an attribute and relationship

I am trying to map same column to be an attribute and a relationship (for reasons that have to do with legacy data) using following mapping: References(x => x.BaseProductTemplate, "ProductCodeTxt"); Map(x => x.DescriptionCode, "ProductCodeTxt") .CustomType(typeof(TrimmedStringUserType)); but "System.IndexOutOfRangeEx...

nHibernate query with reference table

Hi! I'm having a problem with fluent-nhibernate and criteria. I have the following setup. class AMap : ClassMap<A> { Id(x => x.Id); ... HasMany<Connection>(x => x.Connection).Inverse().ReadOnly(); } class BMap : ClassMap<B> { Id(x => x.Id); ... HasMany<Connection>(x => x.Connection).Inverse().ReadOnly(); } class CM...

How do I save an entity with a bidirectional relationship in Fluent NHibernate without setting both sides?

I have two entities: public class Parent() { public ICollection<Child> Children { get; set; } } public class Child() { public Parent Parent { get; set; } } The mapping looks like so: public class ParentMap : ClassMap<Parent> { HasMany(x => x.Children).Cascade.All().Inverse(); } public class ChildMap : ClassMap<Child> { ...

How to look up an NHibernate entity's table mapping from the type of the entity?

Once I've mapped my domain in NHibernate, how can I reverse lookup those mappings somewhere else in my code? Example: The entity Pony is mapped to a table named "AAZF1203" for some reason. (Stupid legacy database table names!) I want to find out that table name from the NH mappings using only the typeof(Pony) because I have to write a ...

How to refer to enum values inside nhibernate formula mapping specification?

Dear ladies and sirs. I have two entities types: RunContainer parent entity type Run child entity type Run has a property Status, which is of type RunStatus, like so: public enum RunStatus { Created, Starting, // ... } public class Run { public int ContainerId { get; private set; } // ... public RunStatus Status { get...

nHibernate Mapping Question

I have the following tables with a one to many relationship one list: List ---- Id Name Type etc... ListItem ---- Id ListId Label etc.. I have the following classes: public class List { public Guid Id{get;set;} public IList<ListItem> {get;set;} } public class ListItem { public Guid Id{get;set;} public string...

Nhibernate/Hibernate, lookup tables and object design

Hi, I've got two tables. Invoice with columns CustomerID, InvoiceDate, Value, InvoiceTypeID (CustomerID and InvoiceDate make up a composite key) and InvoiceType with InvoiceTypeID and InvoiceTypeName columns. I know I can create my objects like: public class Invoice { public virtual int CustomerID { get; set; } public virtual ...

How do I map to a parent or child in the same table with NHibernate?

Lets suppose that I have a Category table with a column that holds the id of a parent or child category from the same table. This design would allow me to have unlimited levels of Categories, or unlimited levels in a thread, for example. How can I map this relationship with NHibernate? Are there any disadvantages or warnings that I shou...

Need help with NHibernate / Fluent NHibernate mapping

Let's say your have the following table structure: ============================== | Case | ============================== | Id | int | | ReferralType | varchar(10) | +---------| ReferralId | int ...

How To Make NHibernate Automatically change an "Updated" column

I am applying NHibernate to an existing project, where tables and columns are already defined and fixed. The database is MS-SQL-2008. NHibernate 2.1.2 Many tables have a column of type timestamp named "ReplicationID", and also a column of type datetime named "UpdatedDT". I understand I might be able to use the <timestamp> element of t...

NHibernate querying on any-associations meta-value

I have a collection of entities with an any-association, like this: public class CreatedLog { public string Message { get; set; } public EntityBase CreatedEntity { get; set; } // an association to any entity } Is there a way - through HQL or Criteria API - to find only the log entries, that are for a specific entity-type? Lik...

Nhibernate mapping

Hi All I am trying to map Users to each other. The senario is that users can have buddies, so it links to itself I was thinking of this public class User { public virtual Guid Id { get; set; } public virtual string FirstName { get; set; } public virtual string LastName { get; set; } public virtua...