SQL Anywhere DotNet 实体
• 显示表Customers的数据
– // 建立实体对象实例
– //SADemoModel.SADemoEntities
– var saEntities = new SQLAnyEDM.SADemoEntities();
– // 从实体对象中检索数据
– var customers = saEntities.Customers;
– // 将数据与 data grid 关联
– customersBindingSource.DataSource = customers;
SQL Anywhere DotNet 实体
• 通过SQL查询数据
– var saEntities = new SQLAnyEDM.SADemoEntities();
– // Query EDM using the EntityClient provider and Entity SQL
– var saConn = new System.Data.EntityClient.EntityConnection(\"Name=SADemoentities\");
– var saCmd = new System.Data.EntityClient.EntityCommand(
– @\"select distinct p.Name from SADemoEntities.Products as p\", saConn);
– saConn.Open();
– var saReader =
– saCmd.ExecuteReader(System.Data.CommandBehavior.SequentialAccess);
– // Loop through result set & add product name to the list box
– listBox1.Items.Clear();
– while (saReader.Read())
– {
– listBox1.Items.Add(saReader.GetString(0));
– } // while
SQL Anywhere DotNet 实体
• 通过对象服务查询数据
– var saEntities = new SQLAnyEDM.SADemoEntities();
– // Query EDM using the Object Services
– var contacts = saEntities.CreateQuery<System.Data.Common.DbDataRecord>(
– @\"select c.GivenName, c.Surname from SADemoEntities.Contacts as c\");
– // Add the contact's first and last names to the list box
– listBox2.Items.Clear();
– foreach (var record in contacts)
– {
– listBox2.Items.Add(
– record.GetString(0) + \" \" + record.GetString(1));
– } // foreach
SQL Anywhere DotNet 实体
• 通过对象LINK查询数据
– var saEntities = new SQLAnyEDM.SADemoEntities();
– // Query EDM using LINQ to entities
– var orders = from o in saEntities.SalesOrders where o.Region == \"Central\"
select o;
– // Add the sales order's number and date to the list box
– listBox3.Items.Clear();
– foreach (var so in orders)
– {
– listBox3.Items.Add(
– \"Order #\" + so.ID + \" placed on \" + so.OrderDate);
– } // foreach
–
0 comments
Post a comment