Search code examples
sql-serversimple.data

Simple.Data Lazy Loading Error


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?


Solution

  • This was a bug in Simple.Data. It is fixed in 0.14.0.3, on Nuget now.