简体   繁体   English

DbSet、实体框架和获取集

[英]DbSet , Entity Framework and Get Set

I am setting up a database using Entity Framework and wanted a bit of clarification regarding creating a DbSet for one of my models.我正在使用 Entity Framework 设置数据库,并希望对为我的一个模型创建 DbSet 进行一些说明。

public DbSet<Customer> CustomersTable { get; set; }

I noticed that the DBset (table) only gets created only if I include the { get;我注意到只有在我包含{ get;时才会创建 DBset(表)。 set;放; } and then add migration. }然后添加迁移。 Why is this { get;为什么这是{get; set;放; } necessary to be included? }必须包括在内?

EF Migrations performs an analysis of your codebase prior to creating a migration, which is why your codebase must compile successfully in order to create a migration. EF Migrations 在创建迁移之前对您的代码库进行分析,这就是您的代码库必须成功编译才能创建迁移的原因。 This analysis is based upon rules and structures, much like most of the language transformations from source to object code.这种分析基于规则和结构,就像从源代码到 object 代码的大多数语言转换一样。 EF is no different.英孚也不例外。 Syntactically in order to create a migration script that includes new tables, its not the declaration of a class, its the combination of a property with get/setters that makes the table creation work.从语法上讲,为了创建包含新表的迁移脚本,它不是 class 的声明,它是属性get/setter 的组合,使表创建工作。

No black magic, just rules.没有黑魔法,只有规则。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM