I've been getting this error in my project. Been stuck for a month now. The problem is, I'm working on a enhancement of an existing project and the domain layer is really complex with more than 50 tables, so I'm unable to pinpoint the root cause.
The funny thing is, if the project where all the domain classes resides are within the main solution, the error occurs. But when I copy the project out and build it, copy the dll to the web application bin folder, it works without error. Exactly the same code. Other team members also do not experience this error.
Also, when I get the original source code before our development from TFS, the same error occurs. We have been able to do development without any error at least in 2 weeks in the beginning. So is it possible the SQL DB causing the error?
So I'm wondering if it's an EF bug. Any pointers to help me debug or find out the culprit domain class?
Here's the error screenshot.
http://imageshack.us/photo/my-images/10/8a1w.jpg/
--UPDATE-- The error is on the context.Database.Initialize when the web app is started.
Managed to find the entity causing the problem. a. It's TPT + TPH b. 2 tables having the same foreign key property name, in my example below, it's the WorkerBenefit property.
It's been reported here: http://entityframework.codeplex.com/workitem/677. And it states Release: 6.0.0, means I have to use EF6?
[Table("Person")]
public abstract class Person
{
public int Id { get; set; }
public string PersonNumber { get; set; }
}
[Table("FullTimeWorker")]
public class FullTimeWorker : Person
{
public string FullTimeWorkerProperty { get; set; }
[ForeignKey("WorkerBenefit")]
public int WorkerBenefitId { get; set; }
[ForeignKey("WorkerBenefitId")]
public virtual WorkerBenefit WorkerBenefit { get; set; }
}
[Table("PartTimeWorker")]
public class PartTimeWorker : Person
{
public string PartTimeWorkerProperty { get; set; }
[ForeignKey("WorkerBenefit")]
public int WorkerBenefitId { get; set; }
[ForeignKey("WorkerBenefitId")]
public virtual WorkerBenefit WorkerBenefit { get; set; }
}
public class MorningShiftWorker : PartTimeWorker
{
public string MorningShiftWorkerProperty { get; set; }
}
public class EveningShiftWorker : PartTimeWorker
{
public string EveningShiftWorkerProperty { get; set; }
}