Oracle ODP.Net和EF CodeFirst - edm.decimal错误 [英] Oracle ODP.Net and EF CodeFirst - edm.decimal error

查看:160
本文介绍了Oracle ODP.Net和EF CodeFirst - edm.decimal错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下简单的实体:

public class Something{
    [DatabaseGenerated(DatabaseGeneratedOption.Computed)]
    public int ID { get; set; }
    public string NAME { get; set; }
    public int STATUS { get; set; }
}

如您所见,我不希望从数据库,但我将手动输入。这是我的DbContext类:

As you can see, I do not want the ID is generated from the database but I'm going to enter manually. This my DbContext class:

public class MyCEContext : DbContext {
    ...
    public DbSet<Something> Somethings { get; set; }

    protected override void OnModelCreating(DbModelBuilder modelBuilder) {
        string dbsch = "myce";
        modelBuilder.Entity<Something>().ToTable("SOMETHING", dbsch);
    }
}

这里没有什么特别的。但是这个代码失败:

There is nothing special here. But this code fails:

            using (MyCEContext ctx = new MyCEContext()) {
                Something t = new Something();
                t.ID= 1;
                t.NAME = "TEST";
                t.STATUS = 100;

                ctx.Somethings.Add(t);
                ctx.SaveChanges();
            }

这是错误:

指定的值不是Edm.Decimal类型的实例

通常,EF尝试发送一个值到一个int主键字段,我得到edm.decimal错误。

In general, allways EF try to send a value to an int primary key field, I get the edm.decimal error.

任何帮助?

推荐答案

正如我在以前的回答中所说的那样,我找到了更好的解决方案,这很奇怪,但它的作品

As I commented on previous answer, I've found better solution, it is strange, but it works

protected override void OnModelCreating(System.Data.Entity.DbModelBuilder modelBuilder)
        {
            base.OnModelCreating(modelBuilder);

            modelBuilder.Entity<TestEntity>().ToTable("TESTENTITY", "SCHEMENAME");
            modelBuilder.Entity<TestEntity>().Property(p => p.Id).HasColumnName("ID").HasColumnType("INT");
            modelBuilder.Entity<TestEntity>().Property(p => p.TestDateTime).HasColumnName("TESTDATETIME");
            modelBuilder.Entity<TestEntity>().Property(p => p.TestFloat).HasColumnName("TESTFLOAT");
            modelBuilder.Entity<TestEntity>().Property(p => p.TestInt).HasColumnName("TESTINT");
            modelBuilder.Entity<TestEntity>().Property(p => p.TestString).HasColumnName("TESTSTRING");
        }

和TestEntity看起来像这样

and TestEntity looks like this

public class TestEntity
    {
        public int Id{ get; set; }

        public string TestString { get; set; }

        public int TestInt { get; set; }

        public float TestFloat { get; set; }

        public DateTime TestDateTime { get; set; }
    }

这篇关于Oracle ODP.Net和EF CodeFirst - edm.decimal错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆