Simple.Data 延迟加载错误
我一直在玩 Simple.Data 并遇到了一些我无法理解的东西。
在我的数据中,我有三个表:Hotel、Project 和 ProjectMilestone。一家酒店可以有多个项目,一个项目可以有多个项目里程碑。我正在使用 SQL Server,表以标准方式通过外键关联。
使用 Simple.Data 时,以下代码将不起作用:
var db = Database.Open();
var hotels = db.Hotel.All().Take(100);
foreach (var hotel in hotels)
{
foreach (var project in hotel.Project)
{
foreach (var projectMilestone in project.ProjectMilestone)
{
//Do something here
}
}
}
它会抛出一个错误,内容如下:
“Simple.Data.SimpleRecord”不包含“Project”的定义
但是,以下代码确实有效:
var db = Database.Open();
var hotel = db.Hotel.FindByHotelID(1);
foreach (var project in hotel.Project)
{
foreach (var projectMilestone in project.ProjectMilestone)
{
//Do something here
}
}
我根本不明白这一点。在我看来,如果第二个有效,第一个也应该有效。 All().Take(100) 返回的集合是否与 FindByHotelID(1) 返回的集合相同?浏览一下类型,看起来应该是这样。
有人以前见过这个吗?
I've been playing around with Simple.Data and have run across something that I can't understand.
In my data, I have three tables: Hotel, Project, and ProjectMilestone. A Hotel can have multiple Projects and a Project can have multiple ProjectMilestones. I am using SQL Server and the tables are related by foreign keys in the standard way.
When using Simple.Data, the following code will not work:
var db = Database.Open();
var hotels = db.Hotel.All().Take(100);
foreach (var hotel in hotels)
{
foreach (var project in hotel.Project)
{
foreach (var projectMilestone in project.ProjectMilestone)
{
//Do something here
}
}
}
It throws an error that says:
'Simple.Data.SimpleRecord' does not contain a definition for 'Project'
However, the following code does work:
var db = Database.Open();
var hotel = db.Hotel.FindByHotelID(1);
foreach (var project in hotel.Project)
{
foreach (var projectMilestone in project.ProjectMilestone)
{
//Do something here
}
}
I don't understand this at all. It seems to me that if the second one works the first one should as well. Is the collection returned by the All().Take(100) not a collection of the same thing that FindByHotelID(1) returns? Looking through the types, it looks like they should be.
Anyone seen this before?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是 Simple.Data 中的一个错误。现在在 Nuget 上的 0.14.0.3 中已修复。
This was a bug in Simple.Data. It is fixed in 0.14.0.3, on Nuget now.