Entity Framework 中 Schema是什么

在使用Entity Framework时,会注意到下面这句:

protected override void OnModelCreating(DbModelBuilder modelBuilder)
{

    modelBuilder.HasDefaultSchema("DEV");
..... }

如果是sql server的话,写上dbo. 就行了

如果是oracle的话,写上“用户名”。

如果schema是用户的话,那为什么不叫HasDefaultUser呢? 非要叫个schema,弄的我都不知道怎么翻译它!

我们再来看,在数据迁移的过程生成的语句:

CreateTable(
                "DEV.BackgroundJobs",
                c => new
                    {
                        Id = c.Long(nullable: false, identity: true),
                        JobType = c.String(nullable: false, maxLength: 512),
                        JobArgs = c.String(nullable: false),
                        TryCount = c.Short(nullable: false),
                        NextTryTime = c.DateTime(nullable: false),
                        LastTryTime = c.DateTime(),
                        IsAbandoned = c.Boolean(nullable: false),
                        Priority = c.Byte(nullable: false),
                        CreationTime = c.DateTime(nullable: false),
                        CreatorUserId = c.Long(),
                    })
                .PrimaryKey(t => t.Id)
                .Index(t => new { t.IsAbandoned, t.NextTryTime });

更加坚定了我的判断 ,schema就是用户名.

然而,经过一翻百度... 终于颠覆了我的认识。

DEV.BackgroundJobs。这里的DEV不是用户,是schema.

总的来看:

1. 用户user不是管理表的,user只是负责连接数据库的。别把它想的那么复杂。

2. schema是管理数据库对象的,当然包括表了,还有packages functions proceures等。

总结一句:

A USER may be given access to SCHEMA OBJECTS owned by different USERS. (https://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:6162110256950)

但这里也解释不了为什么user和schema会重名。

原来,当在数据库中创建了一个用户的时候,会自动创建一个同名的schema.

引用上文的话:

once you create a user in the database -- there is a schema. it is empty, but there is a schema. 

In fact, we have the concept of a schemaless user (user is stored outside the database, in an ldap respository for example). Here, there is no schema, not even the empty one. 

后面这句我选择忽略,很少用到。

所以最后用这位Tom大叔的话,做一个总结:他们是完全可相互替换使用

in oracle for all intents and purposes they are 100% interchangeable. 
原文地址:https://www.cnblogs.com/hankuikui/p/7767244.html