如何在Winform C#中使用EntityFramwork Jet库

时间:2019-07-01 16:27:04

标签: c# entity-framework scaffolding jet

我在Winform C#中使用 EntityFramwork jet库,当我尝试通过以下示例使用它时,出现此错误: Object reference not set to an instance of an object.

所有值都有数据,但是它仍然给我错误。

我使用的数据库是访问权限

C#中的鳕鱼:

var Db = new ModelContext();
foreach (var item in Db.BuyFactorWithTag.ToList())
{
       ErrorAlert(item.FkInventoryNavigation.FkCarNavigation.FullName);
}

BuyFactorWithTag

public partial class BuyFactorWithTag
{
        public BuyFactorWithTag()
        {

        }

        public double PkBuyFactor { get; set; }
        public string FactorNumber { get; set; }
        public int? FkSeller { get; set; }
        public int? FkInventory { get; set; }

        public virtual Inventory FkInventoryNavigation { get; set; }
  }

库存

public partial class Inventory
    {
        public Inventory()
        {
            BuyFactorWithTag = new HashSet<BuyFactorWithTag>();
        }

        public int PkInventory { get; set; }
        public int? FkCar { get; set; }
        public int? FkColor { get; set; }
        public int? Count { get; set; }

        public virtual Car FkCarNavigation { get; set; }
        public virtual CarColor FkColorNavigation { get; set; }
        public virtual ICollection<BuyFactorWithTag> BuyFactorWithTag { get; set; }
    }

汽车

public partial class Car
    {
        public Car()
        {
            Inventory = new HashSet<Inventory>();
        }

        public int PkCar { get; set; }
        public string CarName { get; set; }
        public string CarModel { get; set; }
        public string FullName { get; set; }
        public DateTime? CreateDate { get; set; }

        public virtual ICollection<Inventory> Inventory { get; set; }
    }

我使用以下方法创建模型:

Scaffold-DbContext -Connection "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\database.mdb;Jet OLEDB:Database Password=*****" -Provider EntityFrameworkCore.Jet -o Package\Database -f

正在访问中的表BuyFactorWithTag: enter image description here

Access中的表清单: enter image description here

可访问的桌车enter image description here

0 个答案:

没有答案