FluentNHibernate, HasMany e mappatura 1aN

mercoledì 13 giugno 2012 - 14.52
Tag Elenco Tags  C#  |  .NET 3.5  |  Oracle 11g

volperubbia Profilo | Senior Member

Ciao a tutti,
sto usando FluentNHibernate e vorrei mappare una relazione una molti fra due entità
del mio dominio.

using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using FluentNHibernate.Mapping;

public class Parent
{
[Id]
public virtual int Id { get; set; }
public virtual string Description { get; set; }
public virtual IList<Parent> Children { get; set; }
}
public class ParentMap : ClassMap<Parent>
{
public ParentMap()
{
Table("TBL_PARENT");
Id(x => x.Id, "ID");
Map(x => x.Description, "DESCRIPTION");
HasMany<Child>(s => s.Children);
}
}
public class Child
{
[Id]
public virtual int Id { get; set; }
public virtual string Description { get; set; }
public virtual Parent Parent { get; set; }
}
public class ChildMap : ClassMap<Child>
{
public ChildMap()
{
Table("TBL_CHILD");
Id(x => x.Id, "ID");
Map(x => x.Description, "DESCRIPTION");
References(x => x.Parent, "PARENT").NotFound.Ignore();
}
}

Mi da problemi HasMany<Child>(s => s.Children), o ritorna "illegal access to loading collection" o genera una stringa sql non corretta. Qualche idea su come usare il costrutto?

Grazie mille,
Davide
Partecipa anche tu! Registrati!
Hai bisogno di aiuto ?
Perchè non ti registri subito?

Dopo esserti registrato potrai chiedere
aiuto sul nostro Forum oppure aiutare gli altri

Consulta le Stanze disponibili.

Registrati ora !
Copyright © dotNetHell.it 2002-2024
Running on Windows Server 2008 R2 Standard, SQL Server 2012 & ASP.NET 3.5