Search code examples
c#sqlvarcharormlite-servicestacknotnull

How to have a fixed size not null varchar with OrmLite?


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

enter image description here

enter image description here

I am wondering how can I specify the length for the field. It does not make sense to have 8000 characters for a FirstName for e.g. Also how can I force NOT NULL? The UserName and the Password columns should always have values.


Solution

  • I think you need to look into using annotations: Required and StringLength:

    [Required]
    [StringLength(50)]
    

    So something like:

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

    I think that should do it.

    Good luck.