Generate Entity Data Model from Data Contract
I would like to find a fast way to convert a Data Contract to a Entity Data Model.
Consider the following Data Contract:
[DataContract]
class PigeonHouse
{
[DataMember]
public string housename;
[DataMember]
开发者_如何学C public List<Pigeon> pigeons;
}
[DataContract]
class Pigeon
{
[DataMember]
public string name;
[DataMember]
public int numberOfWings;
[DataMember]
public int age;
}
Is there an easy way to automatically create an ADO.NET Entity Data Model from this code?
No - because the data contract doesn't necessarily correspond 1:1 to a database table or an EDM entity.
What you could try to look into is something like code generation using T4 templates - read the data contract type, reflect over its properties, and generate a database table from it, or just an EDM entity (which could then be turned into a database table).
But I'm not aware of anything that does this out of the box.
I would agree with @marc_s that generating a data base / structure from a data contract would not be the best idea. It becomes difficult with larger or more complex data contracts. I had a similar problem a few days ago but it was the other way round, using the database to create a data contract.
Here are some rules I put forward.
精彩评论