Can EF Fluent Api set a minimum length?

Using the Fluent API seems to have more flexibility.

So, I choose the way to follow, always use the Fluent API to determine the function that it has in db, instead of using annotations.

But here is the problem, I could not find a way to set the minimum length. Is there any way to accomplish this?

And I notice that there is not much to discuss this issue. How popular is the Fluent API?

We hope that we will choose the right part.

+4
source share
2 answers

This is currently not possible with EF. If you really need to set a minimum length, you can do this with the attribute:

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

, , , ( ), 3.

+4

string StringLength

[StringLength(30, MinimumLength = 5)]
public string MyStringProperty { get; set; }

https://msdn.microsoft.com/en-us/library/system.componentmodel.dataannotations.stringlengthattribute%28v=vs.110%29.aspx

+2

Source: https://habr.com/ru/post/1622241/


All Articles