gpt4 book ai didi

c# - 首先在 EF 4.1 代码中以 "schema.tablename"格式映射 POCO,使用 dotconnect for Oracle

转载 作者:太空宇宙 更新时间:2023-11-03 11:31:19 27 4
gpt4 key购买 nike

我有这个实体:

public class MyEntity
{
[Key]
public int Id { get; set; }
public string Name { get; set; }


}

我希望这个实体作为 MySchema.MyEntity 映射到 Oracle 一个 oracle 11g 数据库

    protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Entity<MyEntity>().ToTable("MyEntity", "MySchema");
base.OnModelCreating(modelBuilder);
}

问题是,当我尝试添加实体并执行 SaveChanges 时,它完全忽略了 ToTable() 的架构部分,即使我向类添加了 [Table("MySchema.MyEntity") ] 属性它也被忽略了。无论我做什么,架构将始终是连接字符串的登录名。

        DbConnection con = new Devart.Data.Oracle.OracleConnection(
"User Id=system;Password=admin;Server=XE;Persist Security Info=true;");

架构名称始终是我设置为 UserId 的名称。它只有在我明确写下时才会改变:

    con.ChangeDatabase("MySchema"); //this will only work if the database connection is open...

但我现在确实想把它写下来......

如何实现?

编辑:

天哪...解决方案:

首先:大写模式名称!!!

其次:在官方的 dotconnect 示例中有一行:

config.Workarounds.IgnoreSchemaName = true;

删除它...(这仅在您为所有实体设置模式名称时才有效,否则将使用 oracle 中不存在的“dbo”模式...)

最佳答案

kori0129,你的解决方案是正确的。对应的博文在这里:http://www.devart.com/blogs/dotconnect/index.php/entity-framework-code-first-support-for-oracle-mysql-postgresql-and-sqlite.html .

如果您在使用 dotConnect for Oracle 功能时遇到任何困难,请通过 http://www.devart.com/company/contact.html 联系我们.

关于c# - 首先在 EF 4.1 代码中以 "schema.tablename"格式映射 POCO,使用 dotconnect for Oracle,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7685241/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com