我使用代码优先进行以下映射:
{
/// <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 元素,以便稍后获取其数据进行处理。我究竟做错了什么 ?
路数