开发者

EF4 And POCO Class and Inheritance and Error Mapping and metadata information could not be found for EntityType

开发者 https://www.devze.com 2023-02-06 21:46 出处:网络
I have a POCO Class with name TaskWeek in my business layer and in my presentation layer I defined a new Class:

I have a POCO Class with name TaskWeek in my business layer and in my presentation layer I defined a new Class:

public class TaskWeekUI : TaskWeek
{
    public DateTime EndDate { get; set; }

    public string PersianEndDate
    {
        get
        {
            return UIUtility.ConvertToPersianDate(EndDate);
        }
    }
}

Then I have a method public void Save(List taskweeks) , When I want to call this method I convert a List and call this method:

            using (TaskWeekDA twa = new TaskWeekDA())
            {
                IEnumerable<TaskWeek> tw = MainObjects.twUi.OfType<TaskWeek>();
                twa开发者_Python百科.Save(tw.ToList());
            }

but instead to save I've got this error : Mapping and metadata information could not be found for EntityType

Thanks


Instead of inheriting from TaskWeek is it possible for you to write your methods in a partial class?

For example, write a TaskWeek.part.cs like:

//namespace has to be the same as TaskWeek that your model generated
public partial class TaskWeek
{
    public DateTime EndDate { get; set; }

    public string PersianEndDate
    {
        get
        {
            return UIUtility.ConvertToPersianDate(EndDate);
        }
    }
}

This way the EF has info about the class type, and you have the same functionality as with inheriting (that is, if you're not using inheritance for some other stuff).

0

精彩评论

暂无评论...
验证码 换一张
取 消