ADO.net实体框架动态条件 [英] ADO.net Entity framework Dynamic Where condition
问题描述
我在数据访问层中使用ADO.net实体框架.我想在我的基类MyBaseObject中使用通用方法,例如GetByKey,GetAll,Get,insert,update,delete等. Concreate类将继承此基类.例如:
I am using ADO.net Entity framework in data access layer. i want to use generic methods in my base class MyBaseObject like GetByKey, GetAll, Get, insert, update, delete,etc. Concreate classes will inherit this base class. For Eg:
public class User:MyBaseObject<User>
{
}
下面是我设计的样本基类类型.
Below is the sample base class type i have designed.
public abstract class MyBaseObject<T> where T : System.Data.Objects.DataClasses.EntityObject
{
protected MyBaseObject();
public static int Add(string objectName, T objectToAdd)
{
//logic to add
}
public static T Get(string objectName, int key)
{
//logic to get
}
public static List<T> GetAll(string objectName)
{
List<T> result = null;
using (MyEntities context = new MyEntities(ConUtility.CONNECTION_STRING))
{
result = context.CreateQuery<T>(objectName).ToList();
}
return result;
}
public static List<T> Get(string objectName, unknowntype wherecondition)
{
List<T> result = null;
using (MyEntities context = new MyEntities(ConUtility.CONNECTION_STRING))
{
result = context.CreateQuery<T>(objectName).ToList();
}
return result;
}
}
我想要公共静态List< T> Get(string objectName, unknowntype wherecondition )方法应采用与条件相关的where参数.这些参数是针对T的对象类型的.我还希望这些参数使用AND,OR,EQUAL运算符
支持的.在实体框架中无需使用字符串生成器编写自定义条件的更好方法是什么?
Mr Genius
I want public static List<T> Get(string objectName, unknowntype wherecondition ) method should take where condition related parameters. These parameters are for the object type of T. I also want these where parameters AND, OR, EQUAL operators
supported. What is the better way to achieve this requirement in the Entity framework without writing custom where condition by using string builder?
Mr Genius
推荐答案
尝试在这里提问.
Try asking your question here.
这篇关于ADO.net实体框架动态条件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!