I'm using Entity Framework with ASP.NET MVC 3 and it kindly creates the DB tables for my models for me. That's nice, but there is a simple thing I can't figure out: how do I make some fields NOT NULL in the database without using the [Required] attributes. These are fields that the server must set a value for before saving to the DB, but the user will not need to enter them, hence they are not "required" from a validation point of view.
Add a comment
|
2 Answers
That has nothing to do with your entities. If your entities must be not null they should be required for EF. If requirements for UI are different you need separate view model to represent correct validation rules for UI. Your business logic will be responsible to convert view model to entity and fill additional fields.