I'm using Database first approach and I want to use my own validation I tried to modify generated model, and it works:
But, if I need to update model from DB, of course my validation code overwrites Entity Data Model and attributes disappear. How can I overcome the situation with my own validation?
So what I end up doing that I have created a within same namespace and I have named ClientViewModel
and in this class I have all my custom validation and its works until when I try to save and I get the following error:
The best overloaded method match for 'System.Data.Entity.DbSet.Add(myapp.Models.Client)' has some invalid arguments
here is my controller looks like:
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Create(ClientViewModel client)
{
if (ModelState.IsValid)
{
try
{
using (var context = new db_entities())
{
//more code...
db.Clients.Add(client); //<<<ERROR
db.SaveChagnes();
}
}
}
}