【发布时间】:2014-08-09 13:05:24
【问题描述】:
我的 DBMS (mysql) 中有以下结构:
create table tasks
(
id int auto_increment not null,
primary key (id),
name varchar(200) not null,
unique(name)
);
create table species
(
id int auto_increment not null,
primary key (id),
id_task int,
foreign key (id_task) references tasks(id) on delete cascade,
is_history tinyint not null default 0
);
一个任务可以有一个当前物种(当 is_history=0 时)和历史物种(当 is_history=1 时)。 我创建了以下类:
public class Specie
{
public int Id { get; set; }
public int TaskId { get; set; }
public Task ParentTask { get; set; }
}
public class Task
{
public int Id { get; set; }
public string Name { get; set; }
public ICollection<Specie> CurrentSpecies { get; set; }
public ICollection<Specie> HistSpecies { get; set; }
}
使用代码优先创建映射以将“CurrentSpecies”和“HistSpecies”映射到一个表“species”中的正确方法是什么?在一个字段“is_history”中存在差异?
【问题讨论】:
标签: c# mysql entity-framework ef-code-first