We usually have an int type field, with different numbers, meaning different meanings, in order to make the program more readable and make the UI more convenient, it is a good thing to use Enum to represent the field value.
For example, there is a sex field, an int type, a gender, 1 is a male, 2 is a female, then the value of the database is 1 or 2, but when we show this data to the customer, there is always a need to do some conversion, similar to the following code
if 1 ) alert (" Gender is male "); Else if 2 ) alert (" gender is female ");
Always write such a conversion code is a waste of time things, if you use the Enum type value, it is more convenient, the following to see how to do
First, modify the properties of the field
First, the sex field must be of type int, then the default value is 0, click the edit box of the Enum property, set the value of each enumeration item inside, the syntax is C # syntax, so you can also write
011= male | Woman
Hehe, shemale can also oh, he can be male, can also be female oh, this practice, in fact, the int with binary angle to see, VC friends should often use this technique, so, we in the database search "male" data, is not where data. Sex = = The man wrote this, but where (data. Sex & male) = = That's what the man says, so he chooses both the male and the shemale .
Okay, compile the database DLL, and actually see how to read and write this field in the code.
usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Diagnostics;usingSystem.Drawing;usingSystem.Linq;usingSystem.Text;usingSystem.Threading.Tasks;usingSystem.Windows.Forms;namespacelinqtest1{ Public Partial classForm1:form { PublicForm1 () {InitializeComponent (); } classSysDB:Test.DB.TestDB { Publicsysdb ():Base(@"data source= "" F:\SqliteLinqTest\TestDB """, EntityDB.DatabaseType.Sqlite) { } } Private voidForm1_Load (Objectsender, EventArgs e) { using(vardb =NewSysdb ()) { //add userinfo table Data varuser =NewTest.userinfo (); User. UserName="Zhang San"; User. Sex=test.userinfo_sexenum. Male; Db. Update (user); varUser2 =NewTest.userinfo (); User2. UserName="Liu Fang"; User2. Sex=test.userinfo_sexenum. Female; Db. Update (User2); varUser3 =NewTest.userinfo (); User3. UserName="Li MoU"; User3. Sex=test.userinfo_sexenum. Shemale; Db. Update (USER3); //data for Select males varTable = ( fromMinchdb. UserInfowhere(M.sex & test.userinfo_sexenum. Male) = =test.userinfo_sexenum. MaleSelectm). ToArray (); //Show each data foreach(varUseriteminchtable) {Debug.WriteLine (string. Format ("{0} is {1}", Useritem. UserName, Useritem. Sex)); } /*result of output: Zhang San is male lee is a shemale*/ } } }}
Do not look at the write code when assigning value,user. Sex = test.userinfo_sexenum. Male; To hit so many words, but familiar with the friends of VS should be clear, user. After the sex is finished with the = number , then click the space , vs immediately provide options for you to choose, there is no need to type
. NET open source database design tool MR.E for LINQ (EF 6.1) tutorial (iv) Enum type fields