如何正确使用下面的代码?
public IEnumerable<T> Find(Expression<Func<T, bool>> predicate)
我需要返回一个特定对象的 IEnumerable,但我需要将集合对象转换为 Queryable 并将结果再次转换为 List?
下面是我的实现,不知道对不对,我是用代码对通用存储库进行单元测试的。
public IEnumerable<tbl_SBAem_Attendee> Find(Expression<Func<tbl_SBAem_Attendee, bool>> predicate)
{
var listtblsbaemAttendee = new List<tbl_SBAem_Attendee>();
IEnumerable<tbl_SBAem_Attendee> enumerableAttendee=new List<tbl_SBAem_Attendee>();
for (var i = 0; i < 10; i++)
{
var tblSbAemAttendee = new tbl_SBAem_Attendee
{
AT_AID = i,
AT_Address = "Address1" + i,
AT_Address2 = "Address2" + i,
AT_City = "City",
AT_Email = "rene_florendo2005@yahoo.com.ph",
AT_EventID = null,
AT_FirstName = "Rene" + i,
AT_LastName = "Florendo" + i,
AT_GID = null,
AT_Org = "Rene's Club",
AT_Phone = "888-8888",
AT_Phone2 = "999-8888",
AT_RegID = null,
AT_SendInfo = null,
AT_State = "NJ",
AT_Title = "Mr",
AT_Zip = "4102",
AT_date = null,
AT_opt1 = "option1",
AT_opt2 = "option2",
AT_opt3 = "option3",
AT_opt4 = "option4",
AT_opt5 = "option5",
AT_opt6 = "option6",
AT_userID = null,
AttendeeID = 1
};
listtblsbaemAttendee.Add(tblSbAemAttendee);
}
var result= listtblsbaemAttendee.AsQueryable().Where(predicate);
return result.ToList();
}
非常感谢任何帮助或建议。谢谢你。