// 模型文件的路径,该文件由Entity Model Studio在生成源代码时同时生成 string pathModel = "..."; // 许可证文件路径,在完成试用版注册或者正式版许可证注册后许可证管理器 // 会自动生成该文件 string pathLic = "..."; // CustomModelSqlCS.ED是Entity Model Studio自动生成的类,其中的方法 // CreateContext也是自动生成的。用于完成EMContext对象的生成。 EmContext context = CustomModelSqlCS.ED.CreateContext(pathModel, pathLic); // 构造Sql数据库的连接对象 EMSqlConnection conn = new EMSqlConnection(context); // 构造Sql数据库的命令连接对象 EMSqlCommand comm = new EMSqlCommand(conn); // 使用Eql接口完成查询语句对象的构造 EqlSelect stmt = Eql.Select(CustomModelSqlCS.ED.E7000). From(CustomModelSqlCS.ED.E7000). Where(CustomModelSqlCS.ED.E7000.ID > 10); // 连接数据库。这里无需指明连接字符串,该字符串是在模型文件中配置的。 conn.Open(); // 使用Eql语句对象完成查询实体的ORM功能。参数EntityAffectType.Data用 // 于控制级联的深度。 ReadOnlyCollection result = comm.QueryEntity(stmt, EntityAffectType.Data); // 关闭连接 conn.Cloes();
Company company = new Company(); company.Address = "My Address"; company.CompanyName = "WideUnion Tech"; comm.Save(company);
Company company = new Company(); company.Address = "My Address"; company.CompanyName = "WideUnion Tech"; comm.Save(company); comm.Remove(company);
Company company = new Company(); company.Address = "My Address"; company.CompanyName = "WideUnion Tech"; comm.Save(company); EqlDelete stmt = Eql.Delete(MyContext.Company). From(MyContext.Company). Where(MyContext.Company.ID == company.EntityId); comm.Remove(stmt);
EqlSelect stmt = Eql.Select(MyContext.Company). From(MyContext.Company). Where(MyContext.Company.ID > 10); ReadOnlyCollection company = comm.QueryEntity(stmt);
// 实体方式 comm.SetupRelation(company.HasEmployee, employee); // Eql方式 EqlSelect stmt = Eql.Select(MyContext.Employee). From(MyContext.Employee). Where(MyContext.Employee.ID == employee.EntityId); comm.SetupRelation(company.HasEmployee, stmt);
// 实体方式 comm.BreakRelation(company.HasEmployee, employee); // Eql方式 EqlSelect stmt = Eql.Select(MyContext.Employee). From(MyContext.Employee). Where(MyContext.Employee.ID == employee.EntityId); comm.BreakRelation(company.HasEmployee, stmt);
// 实体方式 comm.TransitRelation(company1.HasEmployee, company2.HasEmployee, employee); // Eql方式 EqlSelect stmt = Eql.Select(MyContext.Employee). From(MyContext.Employee). Where(MyContext.Employee.ID == employee.EntityId); comm.TransitRelation(company1.HasEmployee, company2.HasEmployee, stmt);
EqlSelect stmt = Eql.Select(MyContext.Company). From(MyContext.Company). Where(MyContext.Company.ID > 10); // 使用参数EntityAffectType.Data表示只激活实体本身的数据,不执行任何级联操作。 ReadOnlyCollection company = comm.QueryEntity(stmt, EntityAffectType.Data); // 这时访问HasEmployee属性就会执行懒加载 company[0].HasEmployee.Count.ToString();
EqlSelect stmt = Eql.Select(MyContext.Company). From(MyContext.Company). Where(MyContext.Company.ID > 10); // 使用参数EntityAffectType.Full表示执行所有的级联操作。那么QueryEntity // 方法执行完,所有实体就都被激活了,所以懒加载失效。 ReadOnlyCollection company = comm.QueryEntity(stmt, EntityAffectType.Full); // 这时访问HasEmployee属性不会执行懒加载 company[0].HasEmployee.Count.ToString();
EqlSelect stmt = Eql.Select(MyContext.Company). From(MyContext.Company). Where(MyContext.Company.ID > 10); DbDataReader dr = comm.QueryDataReader(stmt);
EqlSelect stmt = Eql.Select(MyContext.Company). From(MyContext.Company). Where(MyContext.Company.ID > 10); DataSet ds = comm.QueryDataSet(stmt);