I have the following query to read record from database using Join statement in Simple.Data.SqlServer.
var productLineItem = (ProductLineItem) (database.Products.All()
.Select(
database.Products.Name,
database.Products.Price
)
.Join(database.BarCodes)
.On(database.BarCodes.ProductID == database.Products.ID)
.Where(database.BarCodes.BarCode == barCode).FirstOrDefault())
Notice how I have to use FirstOrDefault method as well as wrap the entire statement into parenthesis and then cast it to an object. I do not like this way. I think Simple.Data should be able to work like the following code
ProductLineItemproductLineItem = database.Products.Get()
.Select(
database.Products.Name,
database.Products.Price
)
.Join(database.BarCodes)
.On(database.BarCodes.ProductID == database.Products.ID)
.Where(database.BarCodes.BarCode == barCode);
In the above example I am using Get because I know I will be getting only one record and not a list of records but this query does not work.
How can I achieve what I want using Simple.Data eager loading query and without using those ugly methods?
I'm not sure if what you ideally want is possible, but there is a
Cast()
Linq method you can use to at least continue the query in a functional style and remove the parenthesis you're not keen on: