This code will retrieve all records from the database if the id is null or return records by the available id. Is there a way to combine the query instead of having two separate queries?
// retrieve standard orders
let retrieveStdOrders id =
if id = null then
query{
for row in tool.db.Order_Order_StandardOrder do
select {
Id = row.Id;
BusinessLocationId = row.BusinessLocationId;
ProductOptionId = row.ProductOptionId;
}
}
else
query{
for row in tool.db.Order_Order_StandardOrder do
where(row.Id = id)
select {
Id = row.Id;
BusinessLocationId = row.BusinessLocationId;
ProductOptionId = row.ProductOptionId;
}
}
id
value that could also be a non-value, you should rather use an option type:let retrieveStdOrders id = match id with Some id -> (* do something with the id *) | None -> (* do something without an id *)
or even even shorter:let retrieveStdOrders id = function Some id -> (* ... *) | None -> (* ... *)
. \$\endgroup\$