在遗留数据库模型之后,我得到了类:
public enum ChildType
{
Part1,
Part2,
}
public class Child
{
public virtual int Id { get; set; }
public virtual Parent Parent { get; set; }
public virtual ChildType Type { get; set; }
public virtual bool Flag1 { get; set; }
public virtual bool Flag2 { get; set; }
public virtual char[] Data { get; set; }
public Child()
{
Data = new char[1000];
}
}
public class Parent
{
public virtual int Id { get; set; }
ICollection<Child> Childs { get; set; }
}
每次我需要做
Child usedChild;
if (index < 1000)
{
usedChild = parent.Childs.First(x => x.Type == ChildType.Part1);
}
else
{
usedChild = parent.Childs.First(x => x.Type == ChildType.Part2);
index -= 1000;
}
usedChild.Data[index] = value;
我想
public class Child
{
public virtual int Id { get; set; }
public virtual Parent Parent { get; set; }
public virtual bool Flag1 { get; set; }
public virtual bool Flag2 { get; set; }
public virtual char[] Data { get; set; }
public Child()
{
Data = new char[2000];
}
}
这有可能以某种方式吗?类模型和映射是免费的,db-schema已修复
更新:表格结构
Table Parents
(
parent_id SERIAL NOT NULL,
primary key(id),
)
Table Childs
(
Id SERIAL NOT NULL,
childs_parentid INT,
childs_rowtype INT, // 0, 1
childs_Flag1 INT, // 0, 1
childs_Flag2 INT, // 0, 1
childs_data CHARACTER VARYING(1000)
PRIMARY KEY (Id)
)
每个父行总共有2个子行,一个childs_rowtype = 0
一个childs_rowtype = 1
从不使用id列,除childs_data
之外的所有列对于2个子行完全相同。