EF OR模型的基本使用
来源:互联网 发布:阿里云和腾讯云学生 编辑:程序博客网 时间:2024/05/16 16:03
private void btnGetData_Click(object sender, EventArgs e)
{
using (NorthwindEntities ct = new NorthwindEntities())
{
//查询全部数据;
IQueryable<Customers> cust = ct.Customers as IQueryable<Customers>;
this.dataGridView1.DataSource = cust;
//条件查询
//IQueryable<Customers> cust =from c in ct.Customers where c.CustomerID=="ALFKI" select c;
//this.dataGridView1.DataSource = cust;
}
}
private void btnAdd_Click(object sender, EventArgs e)
{
using(NorthwindEntities ct = new NorthwindEntities())
{
//添加数据
Customers custom = new Customers()
{
CustomerID = "ZHANG",
City = "HZ",
Address = "HZgz",
CompanyName="CompanyName",
Country="Country"
};
ct.Customers.AddObject(custom);
ct.SaveChanges();
IQueryable cust = from c in ct.Customers where c.CustomerID == "ZHANG" select c;
this.dataGridView1.DataSource = cust;
}
}
private void btnDelete_Click(object sender, EventArgs e)
{
using (NorthwindEntities ct = new NorthwindEntities())
{
//删除数据
Customers cust= ct.Customers.First(c => c.CustomerID == "ZHANG");
ct.Customers.DeleteObject(cust);
int i=ct.SaveChanges();
if (i > 0)
{
MessageBox.Show("删除成功");
}
else
{
MessageBox.Show("没找到要删除的数据");
}
IQueryable custs = from c in ct.Customers where c.CustomerID == "ZHANG" select c;
this.dataGridView1.DataSource = custs;
}
}
private void btnEdit_Click(object sender, EventArgs e)
{
//修改数据
using (NorthwindEntities ct = new NorthwindEntities())
{
Customers cust = ct.Customers.First(c => c.CustomerID == "ZHANG");
if (cust != null)
{
cust.City = "杭州";
cust.Address = "杭州";
}
ct.SaveChanges();
IQueryable custs = from c in ct.Customers where c.CustomerID == "ZHANG" select c;
this.dataGridView1.DataSource = custs;
}
}
// 存储过程的使用(edmx设计界面)
private void btnTrans_Click(object sender, EventArgs e)
{
using (NorthwindEntities ct = new NorthwindEntities())
{
System.Data.Objects.ObjectResult<CustOrderHist_Result> result = ct.CustOrderHist("ALFKI");//方式1
result = ct.CustOrderHist("ALFKI");
this.dataGridView1.DataSource = result;
}
{
using (NorthwindEntities ct = new NorthwindEntities())
{
//查询全部数据;
IQueryable<Customers> cust = ct.Customers as IQueryable<Customers>;
this.dataGridView1.DataSource = cust;
//条件查询
//IQueryable<Customers> cust =from c in ct.Customers where c.CustomerID=="ALFKI" select c;
//this.dataGridView1.DataSource = cust;
}
}
private void btnAdd_Click(object sender, EventArgs e)
{
using(NorthwindEntities ct = new NorthwindEntities())
{
//添加数据
Customers custom = new Customers()
{
CustomerID = "ZHANG",
City = "HZ",
Address = "HZgz",
CompanyName="CompanyName",
Country="Country"
};
ct.Customers.AddObject(custom);
ct.SaveChanges();
IQueryable cust = from c in ct.Customers where c.CustomerID == "ZHANG" select c;
this.dataGridView1.DataSource = cust;
}
}
private void btnDelete_Click(object sender, EventArgs e)
{
using (NorthwindEntities ct = new NorthwindEntities())
{
//删除数据
Customers cust= ct.Customers.First(c => c.CustomerID == "ZHANG");
ct.Customers.DeleteObject(cust);
int i=ct.SaveChanges();
if (i > 0)
{
MessageBox.Show("删除成功");
}
else
{
MessageBox.Show("没找到要删除的数据");
}
IQueryable custs = from c in ct.Customers where c.CustomerID == "ZHANG" select c;
this.dataGridView1.DataSource = custs;
}
}
private void btnEdit_Click(object sender, EventArgs e)
{
//修改数据
using (NorthwindEntities ct = new NorthwindEntities())
{
Customers cust = ct.Customers.First(c => c.CustomerID == "ZHANG");
if (cust != null)
{
cust.City = "杭州";
cust.Address = "杭州";
}
ct.SaveChanges();
IQueryable custs = from c in ct.Customers where c.CustomerID == "ZHANG" select c;
this.dataGridView1.DataSource = custs;
}
}
// 存储过程的使用(edmx设计界面)
private void btnTrans_Click(object sender, EventArgs e)
{
using (NorthwindEntities ct = new NorthwindEntities())
{
System.Data.Objects.ObjectResult<CustOrderHist_Result> result = ct.CustOrderHist("ALFKI");//方式1
result = ct.CustOrderHist("ALFKI");
this.dataGridView1.DataSource = result;
}
}
存储过程生成context函数
- iphone环境搭建
- 反编译Apk得到Java源代码
- java.lang.NoSuchMethodError: org.slf4j.helpers.MessageFormatter.arrayFormat(Ljava/lang/String;[Ljava
- 数理逻辑:谓词演算(19)Godel完全定理
- java常见异常
- EF OR模型的基本使用
- C语言如何将每行代码限制在80个字符
- jsp转发和重定向的区别
- 程序员看世界之沙龙感想(10)2012-8-27
- 为什么我的游戏莫名其妙促发了这些事件---- iOS开发之最灵异事件之3
- ubuntu12.04 server 源汇总 IPv6源
- Oracle数据库常见错误锦集之一
- android万能驱动制作方法
- 改变导航栏的颜色