How build query in Linq
-
Hi, I'm starting with Linq. My point is simple, I think. I'm filtering rows in LinqDataSource in event OnSelecting. I want to build a query like this: "select * from t_Rates WHERE (t_Rates.id_Contract = " + ddContract.SelectedValue + ") AND (t_Rates.id_Service = " + ddService.SelectedValue + ") AND (" + strOr +")"; strOr is a string build according if some other control's values are set or not and look like this: "t_Rates.id_UnitRange = 22 OR t_Rates.id_UnitRange = 33 OR t_Rates.id_Season = 34..." and some other OR could be here... Now, I would like to know how o transform this into a very dynamic Linq query construction in order to assing to e.Result inside OnSelecting event. Thanks a lot !!!
-
Hi, I'm starting with Linq. My point is simple, I think. I'm filtering rows in LinqDataSource in event OnSelecting. I want to build a query like this: "select * from t_Rates WHERE (t_Rates.id_Contract = " + ddContract.SelectedValue + ") AND (t_Rates.id_Service = " + ddService.SelectedValue + ") AND (" + strOr +")"; strOr is a string build according if some other control's values are set or not and look like this: "t_Rates.id_UnitRange = 22 OR t_Rates.id_UnitRange = 33 OR t_Rates.id_Season = 34..." and some other OR could be here... Now, I would like to know how o transform this into a very dynamic Linq query construction in order to assing to e.Result inside OnSelecting event. Thanks a lot !!!
You should write a something like this :
alfhv wrote:
"select * from t_Rates WHERE (t_Rates.id_Contract = " + ddContract.SelectedValue + ") AND (t_Rates.id_Service = " + ddService.SelectedValue + ") AND (" + strOr +")";
var query = from q in t_Rates
where t_Rates.id_Contract == ddContract.SelectedValue
&& t_Rates.id_Service == ddService.SelectedValue
selecr q