Monday, 12 August 2013

Inheritance in Entity Framework, InvalidOperationException

Inheritance in Entity Framework, InvalidOperationException

I am attempting to re-structure my WCF service which utilizes EF for
persistence. I am using DB-first method and I am using 3 tables, Players,
Kingdoms, Items. Mapping is as follows (sorry can't add image not enough
rep) Player 1-* Kingdom 1-1 Vault 1-* Item
So my issue is after code-generation created the Item class
namespace Conquest
{
using System;
using System.Collections.Generic;
public partial class Item
{
public int Id { get; set; }
public string Name { get; set; }
public int Movement { get; set; }
public Conquest.Players.Items.ItemType Type { get; set; }
public int VaultId { get; set; }
public virtual Vault Vault { get; set; }
}
}
Now I am attempting to use this class as the base for all of the Items in
my program. Here is an example of an item.
namespace Conquest.Players.Items.Base
{
class BagOfHolding : Item
{
public BagOfHolding()
{
this.Name = "Bag of Holding";
this.Type = ItemType.BagOfHolding;
this.Movement = 0;
}
}
}
However, my problem is that when I attempt to add an item to the public
virtual ICollection<Item> Items { get; set; } hashset collection using
this line of code in the Player constructor
this.CurrentKingdom.Vault.AddItem(new BagOfHolding()); I get an
InvalidOperationException, specifically, Mapping and metadata information
could not be found for EntityType
'Conquest.Players.Items.Base.BagOfHolding'. So since my generated objects
contain no meta tags or mapping information in the code that I can find
how can I go about fixing this?

No comments:

Post a Comment