using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace EFSQLserver
{
class Program
{
static void Main(string[] args)
{
using(ScadaDataEntities1 context = new ScadaDataEntities1())//数据库名
{
//context.Database.Log += c => Console.WriteLine($"sql:{c}"); //显示事务
//类型为表名
ActualData actualData1 = context.ActualDatas.Find(1);//找出主键为1 即使查询
//针对数据库的查询
ActualData actualData2 = context.ActualDatas.FirstOrDefault(u => u.Id == 1);
//new List<int>().FirstOrDefault(u=>u<10);//针对内存数据的Linq to object
//延时查询
var actualDataList = context.ActualDatas.Where(u => u.Id > 10&& u.Id <100 && u.VarName.Length>8);
//actualData1.VarName += "test"; //修改数据中的数据并保存
//foreach (var item in actualDataList)
//{
// Console.WriteLine(item.VarName);
//}
ActualData actualDataNew = new ActualData()
{
InsertTime = DateTime.Now,//Convert.ToDateTime("2005-11-6 16:11:04"),
Value = "5",
VarName = "test",
Remark = "这是测试"
};
context.ActualDatas.Add(actualDataNew);
context.SaveChanges();
ActualData actualData3 = context.ActualDatas.FirstOrDefault(u => u.Remark == "这是测试");
Console.WriteLine(actualData3);
Console.ReadKey();
}
}
}
}
EntityFramework 的DB first
最新推荐文章于 2022-12-02 15:12:12 发布