我在我的表上执行搜索,但是我搜索的Linq字段未在数据库表中找到,而是在模型中创建的。在我搜索的表中,我记录了一个实际上是用户ID的Created_By字段。我显示从另一个表格构建的用户的全名。我希望用户能够搜索CreatedFullName。在我的表中,他们正在搜索结果集显示CreatedFullName,我在其模型中定义,但它不会允许我搜索它,因为它不是在实际的表中。我收到以下错误LINQ to Entities不支持指定的类型成员。 - Linq .Contains
{"The specified type member 'CreateFullName' is not supported in LINQ to Entities. Only initializers, entity members, and entity navigation properties are supported."}
我的模型的字段定义为 -
public string CreateFullName { get; set; }
我的字段添加到结果通过
foreach (DeviceLog x in devicelogs)
{
//Retreive full name for Created By and Modified By
x.CreateFullName = GetFullName(x.CREATED_BY);
if (x.MODIFIED_BY != null)
{
x.ModifiedFullName = GetFullName(x.MODIFIED_BY);
}
}
我的LINQ查询.Where
设置声明
if (!String.IsNullOrEmpty(searchString3))
{
devicelogs = devicelogs.Where(s => s.CreateFullName.Contains(searchString3));
ViewBag.Search = "Search";
}
我的整个模型
public int DeviceLogID { get; set; }
public int DeviceLogTypeID { get; set; }
public int DeviceID { get; set; }
[Required]
[DataType(DataType.MultilineText)]
[Display(Name = "Device Log Entry")]
public string DeviceLogEntry { get; set; }
[Required]
[Display(Name = "Entry Date")]
[DisplayFormat(DataFormatString = "{0:d}", ApplyFormatInEditMode = true)]
public System.DateTime EntryDate { get; set; }
[Display(Name = "Date Created")]
[DisplayFormat(DataFormatString = "{0:d}", ApplyFormatInEditMode = true)]
public System.DateTime DATE_CREATED { get; set; }
[Display(Name = "Created By")]
public string CREATED_BY { get; set; }
[Display(Name = "Date Modified")]
[DisplayFormat(DataFormatString = "{0:d}", ApplyFormatInEditMode = true)]
public DateTime? DATE_MODIFIED { get; set; }
[Display(Name = "Modified By")]
public string MODIFIED_BY { get; set; }
[Display(Name = "Entry Number")]
public int EntryNumber { get; set; }
public bool Corrected { get; set; }
public virtual Device Device { get; set; }
public virtual DeviceLogType DeviceLogType { get; set; }
public virtual ICollection<DeviceLogAudit> DeviceLogAudits { get; set; }
public string CreateFullName { get; set; }
public string ModifiedFullName { get; set; }
什么问题?你如何期望EF搜索表,如果该属性没有相应的列? –
检查答案[这里](https:/ /stackoverflow.com/questions/19791350/linq-cant-use-string-contains),另外,有人应该将此标记为重复 – yorodm
你可以显示你的模型,所有的这个'公共字符串CreateFullname {get; set;}'没有帮助。它不在数据库中?所以你如何在数据库中进行搜索? 你是先使用代码还是先使用数据库? – Munzer