Entity Framework code first adds a limit to positive numbers

I need to add a restriction only for a positive number (0 -...) and limit the numbers as (...- 1).

CreateTable(
   "dbo.Drinks",
   c => new
   {
       Id = c.Int(nullable: false, identity: true),
       Name = c.String(),
       ImageUrl = c.String(),
       Price = c.Int(nullable: false),
       Count = c.Int(nullable: false)
   })
   .PrimaryKey(t => t.Id);
   //.Constraint ???

Something like "unsigned" in MS SQL. Thank.

+4
source share
2 answers

The current configuration of the Entity Framework does not currently support minimum or minimum values, just the length.

You can, however, perform the check this way, via annotations:

[Range(1, int.MaxValue, ...)]
int YourInt{ get; set; }

But this will only be associated with verification during saving, and not with the actual restriction added to the database, as it would be with a quick configuration / migration.

PS

Entity Framework, . , . , , EF.

, ( ) . , , EF , .

+4

Dataannotation:

[Range(0.0, Double.MaxValue)]

0 - , , ?

+1

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


All Articles