- 最後登錄
- 2023-4-9
- 在線時間
- 0 小時
- 註冊時間
- 2007-7-16
- 閱讀權限
- 20
- 精華
- 0
- UID
- 1820716
- 帖子
- 177
- 積分
- 6 點
- 潛水值
- 7641 米
| 如果你忘記伊莉的密碼,請在登入時按右邊出現的 '找回密碼'。輸入相關資料後送出,系統就會把密碼寄到你的E-Mail。 各位大大好:我有二個Model Class
- public class Receipt
- {
- [Key]
- [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
- public Guid ReceiptId { get; set; }
- public string ReceiptNumber { get; set; }
- public Guid SupplierId { get; set; }
- public DateTime ReceiptDate { get; set; }
- public Guid ReceiptType { get; set; } //進貨, 進退
- [MaxLength(10)]
- public string InvoiceNo { get; set; } //發票編號
- public int SubTotal { get; set; } //進貨金額
- public Guid TaxType { get; set; } //稅別
- public int Tax { get; set; }
- public int Amount { get; set; }
- public string ShipAddress { get; set; } //發貨地址, 內定為公司地址
- public int AccountMonth { get; set; } //結帳月份
- public int Discount { get; set; } //折讓
- public string Memo { get; set; }
- public bool IsDelete { get; set; }
- public virtual List<ReceiptDetail> ReceiptDetails { get; set; }
- public Supplier Supplier { get; set; }
- }
複製代碼 及
- public class ReceiptDetail
- {
- [Key]
- public Guid Id { get; set; }
- public Guid ReceiptId { get; set; }
- public int ReceiptSeq { get; set; }
- public Guid ProductId { get; set; }
- public int Quantity { get; set; }
- public int UnitPrice { get; set; }
- public int Amount { get; set; }
- public Receipt Receipt { get; set; }
- public Product Product { get; set; }
- public string Memo { get; set; }
- public bool IsDelete { get; set; }
- }
複製代碼 同時有個dbcontext class
- public class StockContext : DbContext
- {
- public DbSet<Customer> Customers { get; set; }
- public DbSet<Product> Products { get; set; }
- public DbSet<Supplier> Suppliers { get; set; }
- public DbSet<Receipt> Receipts { get; set; }
- public DbSet<ReceiptDetail> ReceiptDetails { get; set; }
- public DbSet<KeyValue> KeyValues { get; set; }
- protected override void OnModelCreating(DbModelBuilder modelBuilder)
- {
- //進貨單設定複合鍵
- modelBuilder.Entity<ReceiptDetail>().HasKey(k => new { k.ReceiptSeq, k.Id, });
- //產品(一) --> 進貨明細(多)
- modelBuilder.Entity<Product>()
- .HasMany(s => s.ReceiptDetails)
- .WithRequired(r => r.Product);
- //進貨單(一) --> 進貨明細(多)
- modelBuilder.Entity<Receipt>()
- .HasMany(s => s.ReceiptDetails)
- .WithRequired(r => r.Receipt);
- }
- }
複製代碼 我想要執行取回一張Recipt及其所關聯的ReceiptDetail, 但ReceiptDetail的IsDelete須為false, 我程式碼如下:
- public static Receipt GetFirstByNumberDes()
- {
- using (var context = new StockContext())
- {
- return context.Receipts.Where(d=>!d.IsDelete).OrderByDescending(d => d.ReceiptNumber)
- .Include(c=>c.ReceiptDetails.Where(s=>!s.IsDelete))
- .FirstOrDefault();
- }
- }
複製代碼 但一直產生錯誤, 訊息如下:
The Include path expression must refer to a navigation property defined on the type. Use dotted paths for reference navigation properties and the Select operator for collection navigation properties.
請問可有那位大大知道問題所在? 謝謝
... |
附件: 你需要登錄才可以下載或查看附件。沒有帳號?註冊 |