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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With