-1
我使用此代码从EntityFrameWork中的数据库中加载数据,但它向我显示此错误。在LINQ中使用Select Statment
实体或复杂类型'DatabaseModel.State'不能在LINQ to Entities查询中构造。
public class StateRepository : BaseRepository
{
public IQueryable Where(System.Linq.Expressions.Expression<Func<Models.DomainModels.State, bool>> predicate)
{
return db.States
.Where(predicate)
.Select(states => new State
{
Id = states.Id,
Country_Id = states.Country_Id,
Name = states.Name,
PhoneCode = states.PhoneCode
});
}
}
var objStateRepository = new StateRepository();
datagrideview1.DataSource = objStateRepository.Where(p => p.Name.Contains(txtSearchState.Text)).ToList();
你已经有一个状态对象。你为什么试图再次创建它*?按照Select(state => state)的方式返回'states'对象,或者完全省略'Select'语句'返回db.States.Where(谓词);'。你是否想要省略某些属性? –