class Program
{
private static void Main(string[] args) {
Smile smile = new Smile();
var users = smile.User;
foreach (User_Model user in users) {
Console.WriteLine(user.S_UserID);
}
//由于加了实体与数据库字段映射
//下面的sql查询用了as转换成映射字段,否则取不出来的
//切记,切记
//Add_DateTime(数据库字段),AddDateTime(映射字段)
var rawSqlUsers =
smile.Database.SqlQuery<Model.User_Model>(
"select id,s_user_id as S_UserID,Sex,Phone,Age,Add_DateTime as AddDateTime,update_datetime as UpdDateTime from users");
foreach (User_Model user in rawSqlUsers) {
Console.WriteLine(user.ID);
}
//command指令如下
//参数id=@p0
int ret = smile.Database.ExecuteSqlCommand("update users set age=-1 where id=@p0", 2);
Console.WriteLine(ret > 0);
//两个参数
int ret1 = smile.Database.ExecuteSqlCommand("update users set age=-1 where id=@p0 and s_user_id=@p1", 12,"kangwl");
Console.WriteLine(ret > 0);
var auser =
smile.Database.SqlQuery<Model.User_Model>(
"select id,s_user_id as S_UserID,Sex,Phone,Age,Add_DateTime as AddDateTime,update_datetime as UpdDateTime from users where id=@p0",
12);
Console.WriteLine(auser.First().Age);
Console.Read();
}
}