views:

66

answers:

1

I have a LINQ-to-SQL DataContext that represents a parent-child relationship of Products to Prices. I'm iterating through a list of products and retrieving the prices for each one. The problem is that the tables behind both the Products and Prices contain a list of Products or Prices for multiple environments, determined by a 3 field complex key. I want to retrieve the Products and Prices for only one of those environments.

I can do this be specifying a long where clause in each LINQ query consisting of the product key and the 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'd like to be able to do is to specify the Client, SalesOrg, and DistributionChannel globally for the DataContext so that all I need to specify in the query itself is the Product ID (MaterialNumber). That way when I starting querying our Production environment a simple change to the DataContext will change what environment I'm querying.

Is this possible? Either a brief code sample or pointers to the background theory would be wonderful!

A: 

You could have a pre-written Expression<T> which you then have those values in it:

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

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

Slace
That was my thinking, but I'm not sure where to set those values within the partial class.
cori
you should create a separate code file for your bits. Keep in mind that the .designer files are auto generated so you should never edit them!
Slace