Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 487
Moslem Ben Dhaou Avatar asked Jan 15 '23 08:01

Moslem Ben Dhaou


1 Answers

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.

like image 122
sgeddes Avatar answered Jan 17 '23 02:01

sgeddes