我在 Visual Studio 中使用实体框架向导创建了一个 db-model。有 2 个表(job、stocktype)与表 stocktype2job 相互关联。
Job <------- no direct relation / navigation property --------> StockType
| |
| |
---------------------> StockType2Job ----------------------------->
使用作业对象,我可以做这样的事情......
EntitiesObject db = new EntitiesObject();
Job job = db.Jobs.SingleOrDefault(j => j.IdJob == 40);
List<StockType> stockTypes = new List<StockType>;
foreach (StockType2Job st2j in job.StockType2Jobs)
{
stockTypes.add(st2j.StockType);
}
那应该工作得很好。但是有没有办法在工作实体中创建一个导航属性,这样我就可以写这样的东西了?
EntitiesObject db = new EntitiesObject();
Job job = db.Jobs.SingleOrDefault(j => j.IdJob == 40);
List<StockType> stockTypes = job.StockTypes; // <<-----
谢谢你的帮助阿波