本文转载自
ltt1987
查看原文
2007-07-17
189
问题/
简单/
求助
IoC中,我的兩個表是這樣設計的
Table1:
id 主鍵
classid 關聯到Table2的id
info 信息
Table2:
id 主鍵
Name
生成的EntityDesigns中
public interface Table1 : Entity
{
[PrimaryKey]
int ID { get; }
int? ClassID { get; set; }
[SqlType("varchar(100)")]
string info { get; set; }
}
public interface Table2 : Entity
{
[PrimaryKey]
int ID { get; }
[SqlType("varchar(100)")]
string name { get; set; }
}
Table1中的ClassID是Table2中ID的外鍵
我想要實例化Table1的時候,能夠直接自動載入Table2中的ID和Name數據。應該如何做呢?
我這樣寫正確嗎?
public interface Table1 : Entity
{
[PrimaryKey]
int ID { get; }
[FkQuery("ID",
Contained
=
true
, LazyLoad
=
false)]
Table2 table2 { get; set; }
[SqlType("varchar(100)")]
string info { get; set; }
}
剛剛了解NBear,希望大家能多多指點。謝謝!