0

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]
    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?

2 Answers 2

3

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.

Sign up to request clarification or add additional context in comments.

2 Comments

I agree data contract doesn't necessarily correspond 1:1 to a database and this is for this reason we have a edmx file to map your data contract to your database. In theory you should be able to generate your EDM from your code as you do from the database. But in theory only because the option doesn't exist.
What would be the way to generate a data contract from a data model then?
0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.