I'm trying to implement Client-Side validation to my DB First project in Entity Framework
5.
I noticed this question and I've seen various other links that describe this MetaDataType
attribute. However, I'm not 100% sure how to set this up.
I see under my .edmx
all of the partial classes that get setup that match the table names and the columns in the table.
namespace Professional.DAL
{
using System;
using System.Collections.Generic;
public partial class LeaderList
{
public LeaderList()
{
this.Answers = new HashSet<Answer>();
}
public int LeaderKey { get; set; }
public string ID { get; set; }
public string AccountName { get; set; }
public long SchoolKey { get; set; }
public Nullable<int> SchoolYear { get; set; }
public virtual School School { get; set; }
public virtual ICollection<Answer> Answers { get; set; }
}
}
The part I need clarification on is do I create another partial class
with the same name in my Models
folder (for example) that has this MetaDataType
attribute:
[MetadataType(typeof(LeaderList.Metadata))]
public partial class LeaderList
{
private sealed class LeaderList
{
[Required(ErrorMessage = "* required")]
public string ID { get; set; }
[Required(ErrorMessage = "* required")]
public string AccountName { get; set; }
[Required(ErrorMessage = "* required")]
public Nullable<int> SchoolYear { get; set; }
[Required(ErrorMessage = "* required")]
public virtual School School { get; set; }
[Required(ErrorMessage = "* required")]
public virtual ICollection<Answer> Answers { get; set; }
}
// Add other similar properties here...
}
Is that what I'm supposed to do? I'm trying to understand this so I can implement it in my next project (as my current project I only did server side validation).
Any links or books for further research is welcomed and appreciated.