Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does the EF Fluent Api can setting the Minimum Length?

It seems use the Fluent API has more flexibility.

So I choose the way to follow always use the Fluent API to determine the feature it have in db instead use the annotations to.

But here is the problem,I couldn't find the way to set the Minimum length. Is there a method to perform this?

And i notice,there are no much topic discuss this way.Is the Fluent API way popular??

Hope we choose the right side.

like image 442
葛厚德 Avatar asked Dec 30 '15 16:12

葛厚德


1 Answers

This is impossible at the moment with EF. If you really have to set a minimum length, you can do it with an attribute though:

[MaxLength(10),MinLength(3)]
public string MyProperty {get; set;}

As the first comment under your question already says, it's probably not very common to have minimum length check in databases (never seen it myself), so this will just throw a validation error when you try to enter a value with a length smaller than 3.

like image 192
Alexander Derck Avatar answered Sep 29 '22 13:09

Alexander Derck