私は自分のテーブルで検索を行っていますが、私が検索している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."}
として私のモデルは、フィールドを定義します - 私は
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
によって結果セットにフィールドを追加
public string CreateFullName { get; set; }
ステートメント
if (!String.IsNullOrEmpty(searchString3))
{
devicelogs = devicelogs.Where(s => s.CreateFullName.Contains(searchString3));
ViewBag.Search = "Search";
}
CreateFullName
がデータベースに存在しないので、私の全体のモデル
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
あなたのモデル、そのすべてを表示できますか?この 'public string CreateFullname {get; set;}'は役に立ちません。データベースにはありませんか?どのようにデータベースを検索すると仮定していますか? 最初にコードまたはデータベースを使用していますか? – Munzer