I let VS create my model from existing SQL tables using EF 4.3.1. Because the DB tables are not final and may change I don't want to set the validation attributes directly into the model file because it gets overwritten when I update the model.
I want to use the MetadataTypeAttribute approach described here: Update Model From Database (Database First)
So I created an external file containing this class:
using System.ComponentModel.DataAnnotations;
namespace PDB.Models
{
[MetadataTypeAttribute(typeof(t_scriptingMetadata))]
public partial class t_scripting
{
}
public class t_scriptingMetadata
{
[Required]
public int platform {get; set;}
[Required]
[StringLength(20)]
public string Projectname {get; set;}
}
}
Unfortunately I get these errors in VS:
- Duplicate EdmEntityTypeAttribute attribute
- Duplicate Serializable attribute
- Duplicate DataContractAttribute attribute
My model that has been generated by VS has exactly these attributes the error message mentions:
[EdmEntityTypeAttribute(NamespaceName="CAWI_STDMGTModel", Name="t_scripting")]
[Serializable()]
[DataContractAttribute(IsReference=true)]
public partial class t_scripting : EntityObject
{
//...
}
What am I doing wrong?