How to have a fixed non-null varchar size with OrmLite?

When declaring a String property in a Poco class, OrmLite will generate a varchar(8000) NULL column for it in the database. eg. I have the following class and the generated table for it:

enter image description here

enter image description here

I am wondering how to specify the length of the field. It makes no sense to have 8000 characters for FirstName, for example. Also how can I force NOT NULL ? The UserName and Password columns must always have values.

+4
source share
1 answer

I think you need to study annotations: Required and StringLength :

 [Required] [StringLength(50)] 

So something like:

 public class Users { ... [Required] [StringLength(50)] public String UserName { get; set; } ... } 

I think he should do it.

Good luck.

+9
source

All Articles