ASP MVC3 Database-first

前端 未结 2 864
渐次进展
渐次进展 2021-01-16 00:49

I use the entity framework for application ASP MVC3. At first I using code-first approach. I created the classes and used attributes to validate the data field



        
相关标签:
2条回答
  • 2021-01-16 01:01

    Here's my $0.02 worth. If you want to validate your model which has been generated by entity framework using the Database first approach then you have to make use of a concept called 'Buddy' class. I believe Scottgu has a great article on that. As you can see the model classes generated by Entity Framework are partial classes meaning to say you can also create your own partial class to hold the so called attributes or to describe the metadata of the generated model. These partial classes will then be combined to form one class at runtime. Please do check out ScottGu's blog here: http://weblogs.asp.net/scottgu/archive/2010/01/15/asp-net-mvc-2-model-validation.aspx

    Hope this answers your question.

    0 讨论(0)
  • 2021-01-16 01:16

    Hard to understand what exactly you mean, but I can recommend reading this.

    The concept of Code First is simple:

    1. You create the classes. In your classes you can use the Required attribute just like you would with the normal Entity Framework
    2. EFCodeFirst creates the database tables for you.
    0 讨论(0)
提交回复
热议问题