views:

485

answers:

1

I am getting this error:

An association from the table dbo.AccountGroup refers to an unmapped class: System.String

This is my entity:

public class AccountGroup
{
    public virtual int Id { get; private set; }
    public virtual string Name { get; set; }
    public virtual string Parent { get; set; }
    public virtual string Description { get; set; }
    public virtual IList<Account> Accounts { get; set; }

    public AccountGroup()
    {
        this.Accounts = new List<Account>();
    }
}

public class Account
{
    public virtual int Id { get; private set; }
    public virtual string Code { get; set; }
    public virtual string Name { get; set; }
    public virtual string Description { get; set; }
    public virtual int Category { get; set; }
    public virtual AccountGroup Group { get; set; }
    public virtual IList<LedgerEntry> LedgerEntries { get; set; }

    public Account()
    {
        this.LedgerEntries = new List<LedgerEntry>();
    }
}

This is my mapping:

    public AccountGroupMap()
    {
        Table("dbo.AccountGroup");
        Id(x => x.Id)
            .Column("Id");
        Map(x => x.Name);
        References(x => x.Parent)
            .Column("Parent");
        Map(x => x.Description);
        HasMany(x => x.Accounts)
            .KeyColumn("GroupId")
            .Inverse()
            .Cascade.All();
    }
}

    public AccountMap()
    {
        Table("dbo.Account");
        Id(x => x.Id)
            .Column("Id");
        Map(x => x.Code);
        Map(x => x.Name);
        Map(x => x.Description);
        Map(x => x.Category);
        References(x => x.Group)
            .Column("AccountGroupId");
        HasMany(x => x.LedgerEntries)
            .KeyColumn("AccountId")
            .Inverse()
            .Cascade.All();
    }

Here are my tables:

CREATE TABLE AccountGroup ( Id int PRIMARY KEY, Name varchar(20), Parent int, Description varchar(20) )

CREATE TABLE Account ( Id int PRIMARY KEY, Code varchar(30), Name varchar(20), Description varchar(20), Category int, AccountGroupId int, FOREIGN KEY (AccountGroupId) REFERENCES AccountGroup (Id) )

+1  A: 

You have

References(x => x.Parent)
        .Column("Parent");

When Parent is defined as

public virtual string Parent { get; set; }

You can't reference a string (unless it's a collection element)

David Kemp

related questions