Phat32
Phat32

Reputation: 31

Entity Framework make a field required based on data

I am working on a C# Silverlight application that uses Entity Framework, I was wondering if there is a way to make a field required based on other pieces of data? To make this more complicated the application has 1 save button that lives outside of the various forms and is added and uses impersonation to keep all the save functions in 1 spot.

Now for example I have member type 1,2,3,4,5,6. If the type is 1-4 then the DOB is required and cannot be left null and will provide the error to support that. But for 5-6 it can be left null.

From what I can tell, the errors are being thrown by Entity itself when it is not given a null to insert into a not null.

Upvotes: 1

Views: 413

Answers (1)

Vlad274
Vlad274

Reputation: 6854

Unfortunately, it is not possible to do what you want.

Think how the underlying schema works, it defines what must be true for every record of the table.

You'll have to enforce that requirement via the business logic of your application.

Upvotes: 1

Related Questions