Question

In some ORM's if there is a one to many relationship the class representing a table normally has a single object with the column's name like 'User' and it populates the property with the contents of the matching table row.

For some reason Subsonic instead chose to add a property ColumnName with the letter s appended to it. It returns IQueryable instead of a single user object.

How do you go about filtering results based on some of the user's properties?

I was trying to do something like this:

 FileRecord thumbnailImageRecord = newsArticleVersion.NewsArticleVersionFileMaps
            .SingleOrDefault(f => f.FileRecords.Single().FilePurpose == 3)
            .FileRecords.Single();

Is there a better way of doing this in the ORM or do I just have to use custom Linq?

Was it helpful?

Solution

This seems to be a shortcoming in SubSonic, and one worthy of a better solution.

Currently one way to do it is to create a partial class of the same name as one of the generated ActiveRecord classes, and add a custom getter.

public partial class child {
  public parent parent {
    get { return parent.SingleOrDefault(x => this.parent_id == x.id); }
  }
}

It should be possible to do this more efficiently by modifying the T4 file, if you have the courage!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top