I am trying to implement Code First (CTP 5) in my WCF Data Service (OData). Its a simple scenario, but I get a HTTP 500 Internal Server Error with no much details开发者_JS百科. I put this on Data Service to show fault error details.
[System.ServiceModel.ServiceBehavior(IncludeExceptionDetailInFaults = true)]
However I still don't see what is going wrong.
In Constructor of my DbContext
implementation I am calling base class with Connection string like below.
public MyContext() : base("MyConnection")
{
}
And I have a simple member in it like this.
public DbSet<MyData> MyData{ get; set; }
I implemented the members of MyData class as needed. All I get in browser is 500 Internal server error without any further details.
What could wrong with my implementation?
After some research, trial and error I found the issue. Putting it here to help others landing in this situation. One of the objects in my Model is being treated as a Complex Type and I am referring to it in another POCO object in my Model as a Collection, which apparently is not supported by EF Code First (which makes sense). This links helped me understand it better.
[Complex Types] http://weblogs.asp.net/manavi/archive/2010/12/11/entity-association-mapping-with-code-first-part-1-one-to-one-associations.aspx
[Conventions in CodeFirst]http://blogs.msdn.com/b/efdesign/archive/2010/06/01/conventions-for-code-first.aspx
Please be aware that there could be many such instances of 500 which is causd due to improper modellign of Objects. Make sure to verify the Conventions and how Code First works in background to understand thee relationships.
精彩评论