Oracle データ プロバイダーおよび TPH 用の DotConnect で Code first EF 6.1 を使用しています。2 つのサブクラスを持つ 1 つのクラスを作成しました。既存のデータベース テーブルにレコードを追加しようとしています。しかし、変更を保存しようとすると、DbUpdateException がスローされます。
例外: {"ORA-06550: 行 4、列 298:\nPL/SQL: ORA-00904: \"Discriminator\": 無効な識別子\nORA-06550: 行 4、列 1:\nPL/SQL: SQL ステートメントは無視されました"}
これが私のコードです:
Person.cs :-----------------
public class Person
{
public Person()
{
Departments= new HashSet<Department>();
}
[Key]
public decimal PersonId { get; set; }
public decimal OfficeId { get; set; }
public decimal PersonTypeId { get; set; }
public virtual Office Office{ get; set; }
public virtual ICollection<Department> Departments{ get; set; }
protected bool success = false;
public virtual bool FindDepartment(int personType)
{
return success;
}
public class PersonHR: Person
{
public override bool FindDepartment(int personType)
{
PersonEntityModel dbcontext = new PersonEntityModel ();
Person p = new Person ();
p.OfficeId= 765;
p.PersonTypeId = personType;
try
{
dbcontext.Persons.Add(p);
dbcontext.SaveChanges();
decimal personId= p.PersonId;
}
catch (DbEntityValidationException dbEx)
{
}
return success;//this is just a test method so don't worry about return.
}
}
public class PersonIT : Person
{
public override bool FindDepartment(int personType)
{
return success;
}
}
}
PersonEntityModel.cs -------------------
public partial class PersonEntityModel: DbContext
{
public PersonEntityModel()
: base("name=PersonEntityModel")
{
}
public virtual DbSet<Office> Offices{ get; set; }
public virtual DbSet<Person> Persons{ get; set; }
public virtual DbSet<Department> Departments{ get; set; }
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Configurations.Add(new PersonMap());
}
}
public class PersonMap: EntityTypeConfiguration<Person>
{
public PersonMap()
{
this.Property(p => p.PersonId).HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);
this.HasMany(p => p.Departments).WithRequired(d=> d.Person).HasForeignKey(d=> d.PersonId);
//table & column mappings
this.ToTable("TABLEPERSON");
this.Property(p => p.PersonId).HasColumnName("PERSONID");
this.Property(p => p.OfficeId).HasColumnName("OFFICEID");
this.Property(p => p.PersonTypeId).HasColumnName("PERSONTYPEID");
//this.Map<DomainObjectModel.ObjectModel.Person.PersonHR>(m => m.Requires("TYPE").HasValue(11));
//this.Map<DomainObjectModel.ObjectModel.Person.PersonIT>(m => m.Requires("TYPE").HasValue(22));
}
}
最後の 2 行がない場合、例外がスローされます: {"ORA-06550: 行 4、列 298:\nPL/SQL: ORA-00904: \"Discriminator\": 無効な識別子\nORA-06550: 行 4、列 1: \nPL/SQL: SQL ステートメントは無視されました"}
最後の 2 行で、次の例外がスローされます: {"ORA-06550: 行 4、列 298:\nPL/SQL: ORA-00904: \"TYPE\": 無効な識別子\nORA-06550: 行 4、列 1: \nPL/SQL: SQL ステートメントは無視されました"}
私はTPHを初めて使用します。上記の問題を解決するにはどうすればよいですか?
また、TPHについて読むのに良い記事を送ってください。このhttp://weblogs.asp.net/manavi/inheritance-mapping-strategies-with-entity-framework-code-first-ctp5-part-1-table-per-hierarchy-tphを読みました。
あなたの助けに感謝、