English 中文(简体)
用EF 4.1代码中的“Schema.tablename”格式对POCOs进行测绘,首先使用Oracle的链接
原标题:Mapping POCOs in "schema.tablename" format in EF 4.1 code first, using dotconnect for Oracle

我有这个实体:

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


}

我希望该实体将MySchema编成Oracle 11g数据库。 MyEntity

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

问题在于,当我试图增加一个实体,而S SaveChanges则完全无视Table(Table)的一部分,即使我补充说,[Table(“MySchema.MyEntity”)也忽略了这一类别。 无论我做什么,Schema永远是扼杀性恩nn的标志。

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

该表名称始终是我确定的用户名称。 只有在我明确指出:

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

但是,我现在想就此写一下。

如何开展这项工作?

http://www.un.org。

Oh man... Solutions:

First : UPPERCASESCHEMANAMES!!!

第二: 在脱节的事例中,有一条线:

config.Workarounds.IgnoreSchemaName = true;

删除...... (只有你为你们所有实体确定图谋名称,否则,将使用在册子中不存在的“船舶”图象,才会奏效。)

最佳回答

kori0129, 你的解决办法是正确的。 相应的博客条款如下:

如果您在甲骨质功能方面遇到任何困难,请通过联系。 。

问题回答

我利用联谊会接过SCHEMA。

我的解决办法是:

   public class MyContext : DbContext
    {
        private string oracleSchema;

        public MyContext()
            : base("OracleConnectionString")
        {
            Database.SetInitializer<MyContext>(null);

            oracleSchema = new System.Data.SqlClient.SqlConnectionStringBuilder(ConfigurationManager.ConnectionStrings["OracleConnectionString"].ConnectionString).UserID.ToUpper();

        }

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            modelBuilder.Entity<Customer>().ToTable(string.Format("{0}.{1}", oracleSchema, "CUSTOMER"));
            modelBuilder.Entity<Invoice>().ToTable(string.Format("{0}.{1}", oracleSchema, "INVOICE"));
            modelBuilder.Entity<Product>().ToTable(string.Format("{0}.{1}", oracleSchema, "PRODUCT"));
            modelBuilder.Entity<Category>().ToTable(string.Format("{0}.{1}", oracleSchema, "CATEGORY"));
            modelBuilder.Entity<Item>().ToTable(string.Format("{0}.{1}", oracleSchema, "ITEM"));

            modelBuilder.Entity<Invoice>().HasRequired(p => p.Customer);

            modelBuilder.Entity<Item>().HasRequired(p => p.Invoice);
            modelBuilder.Entity<Item>().HasRequired(p => p.Product);

            modelBuilder.Entity<Product>()
                        .HasMany(x => x.Categories)
                        .WithMany(x => x.Products)
                        .Map(x =>
                        {
                            x.ToTable("ASS_CATEGORY_PRODUCT", oracleSchema);
                            x.MapLeftKey("ID_CATEGORY");
                            x.MapRightKey("ID_PRODUCT");
                        });

            modelBuilder.Entity<Category>()
                        .HasMany(x => x.Products)
                        .WithMany(x => x.Categories)
                        .Map(x =>
                        {
                            x.ToTable("ASS_CATEGORY_PRODUCT", oracleSchema);
                            x.MapLeftKey("ID_PRODUCT");
                            x.MapRightKey("ID_CATEGORY");
                        });
        }

        public DbSet<Customer> Customers { get; set; }
        public DbSet<Invoice> Invoices { get; set; }
        public DbSet<Item> Items { get; set; }
        public DbSet<Product> Products { get; set; }
        public DbSet<Category> Categories { get; set; }
    }




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签