No subject

Thomas's Avatar

Thomas

04 Nov, 2010 11:00 PM via web

I'm doing some research into which of Entity Framework and (fluent) nHibernate is the best fit for a project. And I've stumbled into some mapping problems. I'm hoping someone here can help me out with a quick solution :)

Here are my entity classes:

public abstract class DisplayItem
{
    public virtual int Id { get; set; }
    public virtual string Name { get; set; }
    public virtual string Description { get; set; }
}

public class Link : DisplayItem
{
    public virtual Node FromNode { get; set; }
    public virtual Node ToNode { get; set; }

    public Link()
    {
    }
}

public class Node : DisplayItem
{
    public virtual IList<Link> LinksFrom { get; set; }
    public virtual IList<Link> LinksTo { get; set; }

    public Node()
    {
        LinksFrom = new List<Link>();
        LinksTo = new List<Link>();
    }
}

I tried first to use the automatic mapper, but that did not work at all. It did create the database and saved data, but the data was not connected correctly. I think the problem comes because a Link contains two instances of Node

I then tried manually mapping it, here is the code I used:

 public class LinkMap : ClassMap<Link>
{
    public LinkMap()
    {
        Id(x => x.Id);
        Map(x => x.Name);
        Map(x => x.Description);
        References(x => x.FromNode);
        References(x => x.ToNode);
    }

}

class NodeMap : ClassMap<Node>
{
    public NodeMap()
    {
        Id(x => x.Id);
        Map(x => x.Name);
        Map(x => x.Description);
        HasMany(x => x.LinksFrom)
            .Cascade.All();
        HasMany(x => x.LinksTo)
            .Cascade.All();
    }
}

Any Idea what I'm doing wrong?

  1. Support Staff 2 Posted by James Gregory on 05 Nov, 2010 07:32 AM

    James Gregory's Avatar

    What happened when you manually mapped it?

Reply to this discussion

Preview Comments are parsed with Markdown. Help with syntax

Attached Files

    You can attach files up to 10MB

    What is the last month of the year?