public class CompareParameter<T>
{
public string FieldName { get; set; }
public T FieldValue { get; set; }
public CompareType CompareType { get; set; }
}
接口
public interface IMongoConnectionFactory
{
int GetCountWithFilter<T>(params object[] param) where T:EntityBase;
}
接口实现
public class MongoConnectionFactory : IMongoConnectionFactory
{
public int GetCountWithFilter<T>(params object[] param) where T : RedBusPlusEntities.EntityBase
{
throw new NotImplementationException();
}
}
商业行为准则
public int GetCustomerCount(int operatorId, int day)
{
Customer c = new Customer();
CompareParameter<int> OpId = new CompareParameter<int>();
OpId.FieldName=GetMemberName.GetName(() => c.OpId);
OpId.FieldValue=operatorId;
OpId.CompareType=CompareType.EQ;
CompareParameter<long> Day = new CompareParameter<long>();
Day.FieldName=GetMemberName.GetName(() => c.Doil);
Day.FieldValue=GetStartDateOfIssue(day);
Day.CompareType = CompareType.GTE;
return _fac.GetCountWithFilter<Customer>(OpId, Day);
}
所以在这里,我传递了两个不同类型的两个PARAM从商业到DAL。所以我把它从object
传入。现在我该如何构建在接口实现中传递的相同类型。尝试了一些与Convert.ChangeType
的方法,但失败了。有人可以帮助我吗?
这将有助于了解你INT GetCountWithFilter(params对象[] PARAM)内做什么,因为它可能比[对象] –
我想其他的东西来传递通过传递参数对象来创建一个mongo过滤器查询。 mongo查询看起来像'var filter = builder.Eq(“cuisine”,“Italian”)&builder。公式(“拉链”,10075);'传递的对象包含用于创建过滤器 – user3132179
的必要的信息和类型,因此你能不能改变你的接口为: 公共接口IMongoConnectionFactory { INT GetCountWithFilter(PARAMS CompareParameter [] PARAM)其中T:EntityBase; } –