I have several Stored Procedures which I use to search the database. Each returns several fields to do with the amount of data found/returned. The models look like this:
// simplified
public abstract class SearchResult {
public int RowCount { get; set; }
public int FilteredRowCount { get; set; }
// other properties
}
public class FooSearch {
public string Id { get; set; }
public string Foo { get; set; }
public SearchResult Result { get; set; }
}
Then in the DBContext I'm using OwnsOne() to link the classes, as per this MS guide
public DbSet<FooSearch> FooSearch { get; set; }
// OnModelCreating
builder.Entity<FooSearch>().OwnsOne(t => t.Result);
Finally I make the SP call:
var searchResult = db.FooSearch.FromSqlRaw("EXECUTE [Search].[Foo] {0}, {1}", foo, bar).ToList();
However this last step is giving me the following error:
System.InvalidOperationException: 'FromSqlRaw or FromSqlInterpolated was called with non-composable SQL and with a query composing over it. Consider calling
AsEnumerableafter the FromSqlRaw or FromSqlInterpolated method to perform the composition on the client side.'
Changing ToList() to AsEnumerable() makes no difference to the result.
If I remove the OwnsOne() and the Result property from the FooSearch class then the SP works and I get results. What is the cause of this issue, and how can I fix it?