0

我使用代码优先进行以下映射:

{
    /// <summary>
    /// Entity Framework Dc.Dc database table object representation
    /// </summary>
    [Table("DCDC", Schema = "MZMESDB")]
    public class EfDcDc
    {
        /// <summary>
        /// Element ID
        /// </summary>
        [Column("ID")]
        public int Id { get; set; }

        /// <summary>
        /// Name of DC
        /// </summary>
        [Column("NAME")]
        public string Name { get; set; }

        /// <summary>
        /// DC Description
        /// </summary>
        [Column("DESCRIPTION")]
        public string Description { get; set; }

        /// <summary>
        /// Foreign Key
        /// </summary>
        public virtual EfSystemDataModule Module { get; set; }

        /// <summary>
        /// Name of module
        /// </summary>
        [Column("ENABLED")]
        public string Enabled { get; set; }
    }
}

{
    /// <summary>
    /// Entity Framework SystemData.Module database table object representation
    /// </summary>
    [Table("SYSTEMDATAMODULE", Schema = "MZMESDB")]
    public class EfSystemDataModule
    {
        /// <summary>
        /// Element ID
        /// </summary>
        [Column("ID")]
        public int Id { get; set; }

        /// <summary>
        /// Name of module
        /// </summary>
        [Column("NAME")]
        public string Name { get; set; }

        /// <summary>
        /// If the module is installed. Char because Oracle does not support boolean
        /// </summary>
        [Column("INSTALLED")]
        public char Installed { get; set; }

        /// <summary>
        /// If the module is enabled. Char because Oracle does not support boolean
        /// </summary>
        [Column("ENABLED")]
        public char Enabled { get; set; }

    }
}

Oracle 表有一个外键:

CREATE TABLE "MZMESDB"."DCDC" ( 
                                "ID" INTEGER NOT NULL , 
                            "NAME" VARCHAR2(64) NOT NULL , 
                            "DESCRIPTION" VARCHAR(256),
                            "MODULE_ID" INTEGER NOT NULL,
                            "MODULE_NAME" VARCHAR(64) NOT NULL,
                            "ENABLED" CHAR NOT NULL, 
                            PRIMARY KEY ("ID") VALIDATE,
                            FOREIGN KEY (MODULE_ID, MODULE_NAME) REFERENCES SYSTEMDATAMODULE(ID, NAME)

编译时没有问题,但在我发出时在 rutime:

MzDbContext dbContext = new MzDbContext();
            EfDcDc configuredDC = new EfDcDc();

            try
            {
                configuredDC = dbContext.efDcDc.FirstOrDefault(item => item.Name == "COMMON_NAME");
            }
            catch (Exception e)
            {
                Debug.WriteLine("Error reading from database. Message: " + e.Message.ToString());
                return false;
            }

我从 Oracle EF 驱动程序收到以下错误:

ORA-00904: \"Extent1\"."\"Module_Id\":Invalid identifier.

我只想检查数据库中是否存在 DcDc 元素,以便稍后获取其数据进行处理。我究竟做错了什么 ?

路数

4

2 回答 2

1

这通常来自无效的列名。在 Oracle 中,所有的列名都是大写的。混合大小写 Module_Id 来自哪里?我只看到您的代码中使用的 ID。

于 2013-08-07T19:47:41.947 回答
0

该问题与 EF 内部机制有关,该机制未将某些内部名称大写...

因此,Oracle 中不存在 Module_Id,因为表字段是 MODEL_ID。我仍在努力解决这个问题......

于 2013-08-07T20:12:31.550 回答