我有這樣的:如何使1:用不同的查詢(LINQ語法)模型之間的多對多關係
型號:
{
[Table("Requests")]
public partial class RequestsModel
{
public RequestsModel()
{
this.CountView = new HashSet<RequestCountViewModels>();
}
[Key]
public int Id { get; set; }
public int? Sender { get; set; }
public int? Type { get; set; }
public string Subject { get; set; }
public string Text { get; set; }
public int? Adtype { get; set; }
public int? Status { get; set; }
[Column(TypeName = "date")]
public DateTime? SDate { get; set; }
[Column(TypeName = "date")]
public DateTime? EDate { get; set; }
public DateTime? RDate { get; set; }
public DateTime? PayDate { get; set; }
public DateTime? RespDate { get; set; }
public long? Counter { get; set; }
public string Tags { get; set; }
public string Maps { get; set; }
public int? AccBy { get; set; }
public virtual ICollection<RequestCountViewModels> CountView { get; set; }
}
[Table("Counter")]
public partial class RequestCountViewModels
{
[Key]
public long Id { get; set; }
[ForeignKey("ParentMdl")]
public int? ReqId { get; set; }
public string IP { get; set; }
public virtual RequestsModel ParentMdl { get; set; }
public DateTime? Time { get; set; }
}
}
的HomeController:
public virtual ActionResult Advs(string id)
{
var model = _requestService.GetAdvertise(Convert.ToInt32(id));
return View(model);
}
RequestsService.cs
個public RequestsModel GetAdvertise(int AdID)
{
return
_ctx.Requests
.AsNoTracking()
.FirstOrDefault(a => a.Id == AdID && a.Type == 1);
}
RequestsConfig.cs
HasMany(a => a.CountView)
.WithRequired(a => a.ParentMdl)
.HasForeignKey(a => a.ReqId);
這些[R我的代碼,現在我要讓RequestCountViewModel關係RequestsModel和之間使從刪除數據庫 檢索相關表中的數據將get請求表,但需要檢索每行的viewcount表並填入ICOLLECTION 幫我!對不起弱英語
抱歉,**從遠程分貝** –
'返回_ctx.Requests.Include(p值=> p.CountView).AsNoTracking()。FirstOrDefault (a => a.Id == AdID && a.Type == 1);' –
@CristianSzpisjak當我編寫.Include(p => p.CountView)時,有紅色下劃線的語法錯誤!說:**不能將lambda表達式轉換爲類型'字符串',因爲它不是委託類型**!我不知道該怎麼辦 ! –