I am performing a search on my table however the Linq field I am searching on is not found in the database table but one that I created in the Model. In the table I am searching I record a Created_By field that is actually a user ID. I display the user's full name that I build from another table. I would like the user to be able to search on CreatedFullName. In my table that they are searching the result set shows CreatedFullName that I defined in its Model however it will not allow me to search it because it is not in the actual table. I receive the following error
{"The specified type member 'CreateFullName' is not supported in LINQ to Entities. Only initializers, entity members, and entity navigation properties are supported."}
My Model defines the field as -
public string CreateFullName { get; set; }
I add the field to the result set by
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);
}
}
My Linq query .Where
statement
if (!String.IsNullOrEmpty(searchString3))
{
devicelogs = devicelogs.Where(s => s.CreateFullName.Contains(searchString3));
ViewBag.Search = "Search";
}
My entire Model
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; }