Can I specify a set of basic parameters for the DataContext Linq-to-sql?

I have a LINQ-to-SQL DataContext that represents the relationship between products and prices between parents and children. I iterate over the list of products and get prices for each. The problem is that tables, arranged by both product and price, contain a list of products or prices for multiple environments, defined by 3 field complex keys. I only want products and prices for one of these environments.

I can do this by specifying a long where clause in each LINQ query that consists of a product key and a complex environment key, something like this:

var price = ( from condition in conditiontype where condition.MaterialNumber == material && condition.Client == "400" && condition.SalesOrg == "1000" && condition.DistributionChannel == "10" select condition.ConditionDetails[0].ConditionValue );

      

what I would like to do is specify the Client, SalesOrg and DistributionChannel globally for the DataContext, so all I need to specify in the request itself is the Product ID (MaterialNumber). This way, when I start to query our production environment, a simple change to the DataContext will change the environment I am requesting.

Is it possible? Either a short code sample or pointers to background theory would be great!

-1


source to share


1 answer


You may have a pre-recorded Expression<T>

one that you have in it:

public Expression<Func<int>> GetPrices = p => // do Lambda here

      



Alternatively, you can put properties in your DataContext (remember this is a partial class , so it's easy to extend), which you set up and then read with your expression.

0


source







All Articles