I am looking into implementing a form a Data Validation on at the Data Layer of my application. I am looking to accept a specific string input into my data model, but am struggling to know how best to implement this.
I am currently looking into whether Fluent API (currently testing EF Core flavor) will facilitate this functionality, or whether I need to consider bringing in Data Annotations into my Data Layer model to ensure the validation can be implemented on all Object Relational Modeling services.
From reading around online, Fluent API is the best course of action as it removes workload from the Data Layer and lets the Data Access layer control and specify the specific rules around how the data will be modeled.
The downside is that I would need to re-implement this for other ORM's (i.e.: NPoco) to meet the rules of this platform.
A bit more on the problem
I have several classes that will have foreign cultured names and strings, and they can be identified by a Language Culture String, using the ISO-639 and ISO-3166 combination. (en-GB, zh-CN)
This is represented by a String in the Data Model.
public abstract class Alias
{
public string Culture { get; set; }
}
Under EF Core, I set up the tables using the OnModelCreating function.
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
var authorAlias = modelBuilder.Entity<AuthorAlias>();
authorAlias.Property("Given").IsRequired().IsUnicode();
authorAlias.Property("Family").IsRequired().IsUnicode();
authorAlias.Property("Middle").IsUnicode();
base.OnModelCreating(modelBuilder);
}
I know .NET Core has the ability to pull down an array of CultureInfo which use the Localization String system I want to implement, but I do not intend the Data Model to check this but to let the Data Access layer validate the data.
How can I ensure that my intended logic can be implemented into the system? And would I need to change to Data Annotations to ensure this logic?