cliff, thanks for suggestion.
But that is how I designed my domain: property is initialized trough
constructor and it's read-only for the rest of the world. I want to enforce
this rule.
protected First() { }
public First(Second second)
{
// ...
}
public virtual Second Second { get; private set; }
On Fri, Aug 13, 2010 at 5:52 PM, cliff vaughn <[email protected]>wrote:
> i don't know if this will help, but your classes seem to be designed a
> bit off. First, in the First.Second setter, you shouldn't be doing
> any adding to lists here. You're going to run into all kinds of
> problems, maybe this one, when NH tries to load that object and sets
> that property. A better design is to have an Add method in Second:
>
> public void Add( First item )
> {
> item.Second = this;
> collectionOfFirst.Add( item );
> }
>
> Also, the collectionOfFirsts should declared be an IList<> instead of a
> List.
>
> cliff
>
> On Fri, Aug 13, 2010 at 10:21 AM, Valeriu Caraulean <[email protected]>
> wrote:
> > I've got into situation where my mappings and domain are throwing to me a
> > FatalExecutionEngineError.
> > I'll be posting the code here, hoping that someone can help me
> understand,
> > I'm doing "unnatural" things with NHibernate or it's a bug somewhere...
> > The exact error I'm getting is:
> >
> > FatalExecutionEngineError was detected
> >
> > Message: The runtime has encountered a fatal error. The address of the
> error
> > was at 0xf8a213a3, on thread 0x660. The error code is 0xc0000005. This
> error
> > may be a bug in the CLR or in the unsafe or non-verifiable portions of
> user
> > code. Common sources of this bug include user marshaling errors for
> > COM-interop or PInvoke, which may corrupt the stack.
> >
> > Example is stripped down to minimum from our project. Names are awkward,
> > scenario probably looks silly, but that's extracted from our real domain.
> > I'm showing only relevant part of classes. For full VS project see
> > http://github.com/vcaraulean/NHibernate.FEEE .
> > Domain: two classes with one-to-many relation. Classes are "aggregate
> > roots", modified individually but in same session/transaction scope.
> Using
> > double dispatch to keep aware one of another.
> > public class First
> > {
> > public First(Second second)
> > {
> > Second = second;
> > }
> >
> > private Second second;
> > public virtual Second Second
> > {
> > get { return second; }
> > private set
> > {
> > second = value;
> > second.AddFirst(this);
> > }
> > }
> > }
> >
> > public class Second
> > {
> > private readonly List<First> collectionOfFirsts;
> >
> > public Second()
> > {
> > collectionOfFirsts = new List<First>();
> > }
> >
> > public virtual IEnumerable<First> CollectionOfFirsts
> > {
> > get { return collectionOfFirsts; }
> > }
> >
> > public virtual void AddFirst(First first)
> > {
> > collectionOfFirsts.Add(first); // Here FatalExecutionEngineError is
> thrown
> > }
> > }
> >
> > Mapping files, FluenNHibernate:
> > public class FirstPersistenceMap : ClassMap<First>
> > {
> > public FirstPersistenceMap()
> > {
> > Id(x => x.Id);
> > References(x => x.Second);
> > }
> > }
> >
> > public class SecondPersistenceMap : ClassMap<Second>
> > {
> > public SecondPersistenceMap()
> > {
> > Id(x => x.Id);
> > HasMany(x => x.CollectionOfFirsts)
> > .Access.ReadOnlyPropertyThroughCamelCaseField();
> > }
> > }
> >
> > Usage, in unit test:
> > using (var session = sessionFactory.OpenSession())
> > using (var tx = session.BeginTransaction())
> > {
> > var second = new Second();
> > session.Save(second);
> >
> > var firstClass = new First(second);
> > session.Save(firstClass);
> > }
> >
> > Two questions:
> > - What I'm doing wrong here?
> > - How can I map it so it will work as expected?
> > Thanks!
> >
> > --
> > You received this message because you are subscribed to the Google Groups
> > "nhusers" group.
> > To post to this group, send email to [email protected].
> > To unsubscribe from this group, send email to
> > [email protected]<nhusers%[email protected]>
> .
> > For more options, visit this group at
> > http://groups.google.com/group/nhusers?hl=en.
> >
>
>
>
> --
> thanks
>
> cliff
>
> --
> You received this message because you are subscribed to the Google Groups
> "nhusers" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected]<nhusers%[email protected]>
> .
> For more options, visit this group at
> http://groups.google.com/group/nhusers?hl=en.
>
>
--
You received this message because you are subscribed to the Google Groups
"nhusers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/nhusers?hl=en.