0

What is the point of specifying configurations (either via data annotations or the fluent API) for Entity Framework if you working with an existing database?

If the database doesn't already exist, then I know the configurations are used to help generate the database (correctly).

Entity Framework can also perform a validation on-demand or prior to saving changes back to the database...and it presumably it uses the configurations for this as well.

Does Entity Framework use the configurations any other reason?

1 Answer 1

1

Yes, creating the DB if not already exists using code first approach is altogether a different approach but the model you create using configuration in your application acts as a logical model same as DB which in turn used as a data access layer for your application. So that, all the transactions like insert/update/delete can happen seamlessly between your application and DB.

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

4 Comments

By "which in turn can be used as a data access layer for your application", do you mean that this information is available in the MetadataWorkspace?
In "So that, all the transactions like insert/update/delete can happen seamlessly between your application and DB", what do you mean by "seamlessly"?
@TysonWilliams, means, say while inserting/deleting if their is a FK present and if you have configured it, then it can act accordingly to maintain the integrity. Forget about EF, even if you are using normal ADO.NET (probably using typed dataset), you have to specify this in code. In case of EF you do it either using fluent API (or) declaratively using data-annotations.
Oh, I think I understand (better) what you are saying. Let me repeat it back to you. Configuration allows you to specify which the FK relationships. EF needs to know these so that it deletes and inserts in the correct order in order to obey the constraints.

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.