试图让我了解实体框架。我有一个包含两个表的数据库,其中包含有关交易的信息。一个包含事务类别信息,并一对一地链接到事务表中(transactions.Category <=> Category.CategoryID)。我可以在填充了类别实体的情况下在内存中创建新事务,但是当我尝试刷新到数据库时,我得到“{”无效对象名称'mEconomyUser.category'。”}”
交易表:
TransactionID uniqueidentifier
UserID uniqueidentifier
Date date
Text nvarchar(250)
Category uniqueidentifier
Amount decimal(18, 0)
类别表:
CategoryID uniqueidentifier
UserID uniqueidentifier
Text nvarchar(50)
这是我的模型:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.Entity;
using System.ComponentModel.DataAnnotations;
namespace mEconomy.Models
{
[Table("transactions", Schema = "mEconomyUser")]
public class Transaction
{
[Key]
public Guid TransactionID { get; set; }
public Guid UserID { get; set; }
public DateTime Date { get; set; }
public string Text { get; set; }
public virtual Category Category { get; set; }
public decimal Amount { get; set; }
}
public class TransactionDBContext : DbContext
{
public DbSet<Transaction> Transactions { get; set; }
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.Entity;
using System.ComponentModel.DataAnnotations;
namespace mEconomy.Models
{
[Table("category", Schema = "mEconomyUser")]
public class Category
{
[Key]
[ForeignKey("Transaction")]
public Guid CategoryID { get; set; }
public Guid UserID { get; set; }
public String Text { get; set; }
public virtual Transaction Transaction { get; set; }
}
public class CategoryDBContext : DbContext
{
public DbSet<Transaction> Categorys { get; set; }
}
}
有什么建议么?