简体   繁体   English

EF Core ToQueryString() 不包括架构

[英]EF Core ToQueryString() does not include schema

I am trying to use SqlDependency, which requires a query as a string which specifies the schema (dbo.[table name]) but EF Core ToQueryString does not include dbo.我正在尝试使用 SqlDependency,它需要将查询作为指定架构(dbo.[表名])的字符串,但 EF Core ToQueryString 不包括 dbo。

Is there another way to get a query from Ef core that includes the dbo keyword or a way to force SqlDependency to accept a more vague query?是否有另一种方法可以从包含 dbo 关键字的 Ef 核心获取查询,或者强制 SqlDependency 接受更模糊的查询?

Entity Framework core doesn't make any assumptions as to which schema you want to use. Entity Framework 核心不会对您要使用的架构做出任何假设。 In Sql Server, usually it'll be dbo , but if you don't specify it, EF will generate schema-less SQL statements.在 Sql 服务器中,通常是dbo ,但如果你不指定它,EF 会生成无模式的 SQL 语句。 That may cause surprises when eg you generate a database under a user that has another default schema than dbo .例如,当您在具有另一个默认模式而不是dbo的用户下生成数据库时,这可能会引起意外。

Lesson I learned when working with EF core:我在使用 EF 核心时学到的教训:

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
    // *Always* specify schema. Otherwise EF will generate schema-less DDL + DML.
    modelBuilder.HasDefaultSchema("dbo");
    ...

This will probably be enough for you.这对你来说可能就足够了。 Yo can also specify the schema per table . Yo 还可以指定每个表的架构。

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

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