Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ADO.NET Entities - Model-first data annotations

I'm using the approach explained here:-

http://blogs.msdn.com/b/adonet/archive/2010/12/06/ef-feature-ctp5-code-first-walkthrough.aspx

I'd like to use the surface designer to develop my model, then use partial classes to include data annotations for validation. However, if I use a partial class and then attempt to reference an existing property the compiler complains that the property already exists.

How do I get over this?


e.g.

public partial class Product
{
    [Required(ErrorMessage="Name is required")]
    public string Name { get; set; }
} 

The compiler says "Name is already defined".

like image 276
Rob Avatar asked Jul 01 '26 15:07

Rob


1 Answers

I just ran across the same problem on how to annotate an entity class that is generated from the Entity Data Model and I found the answer on another stackoverflow thread:

Using System.ComponentModel.DataAnnotations with Entity Framework 4.0

like image 77
Kendrick Avatar answered Jul 05 '26 05:07

Kendrick



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!