如何知道项目是代码优先还是数据库优先? [英] How to know project is code-first or database-first?
本文介绍了如何知道项目是代码优先还是数据库优先?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在现有项目中,我怎么知道它是代码优先还是数据库优先?
In an existing project, how do I know if it's code-first or database-first?
项目有以下代码行:
public class TestDBContext : DbContext
{
public DbSet<Player> Players { get; set; }
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
}
}
项目没有。 edmx
文件。如果需要其他详细信息,我将与您分享。
And project has no .edmx
file. If any other details need I will share.
编辑:
播放器。 cs类
public class Player
{
public int PlayerID { get; set; }
public string PlayerName { get; set; }
}
编辑12.05.2017
如果我从连接字符串
更改了数据库名称
并运行了项目,创建具有新名称的数据库
包含所有表
。
IF I change database name
from connection string
and run project, it creates database with the new name
with all tables
. May be this will be hit for the answer.
推荐答案
如果这是一个数据库优先的项目,则有:
If this is a project is Database-first, there is :
- [name] .edmx图表文件及其[name] .Context.tt& ; .cs
- 每个转换成类的表都隐藏在树中,如.edmx> .tt
- ,在 onModelCreating 中,有一个
抛出新的UnintentionalCodeFirstException()
- [name].edmx diagram file and with it, [name].Context.tt & .cs
- every tables that are translated into class are hidden in tree like .edmx > .tt
- in onModelCreating, there is a
throw new UnintentionalCodeFirstException()
否则,表中的所有类问题都在项目中(没有树)。
If not, all the class issue from the tables are in the project (no tree).
这篇关于如何知道项目是代码优先还是数据库优先?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文