I have entity called Customer and it has three properties:
public class Customer {
public virtual Guid CompanyId;
public virtual long Id;
public virtual string Name;
}
I have also entity called Splitting and it has three properties:
public class Splitting {
public virtual long CustomerId;
public virtual long Id;
public virtual string Name;
}
Now I need to write a method that gets companyId and customerId. The method should return list of splitting that relates to the specific customerId in the companyId. Something like this:
public IList<Splitting> get(Guid companyId, long customrId) {
var res=from s in Splitting
from c in Customer
...... how to continue?
return res.ToList();
}
This question is related to
c#
.net
linq-to-entities
public IList<Splitting> get(Guid companyId, long customrId) {
var res=from c in Customers_data_source
where c.CustomerId = customrId && c.CompanyID == companyId
from s in Splittings_data_srouce
where s.CustomerID = c.CustomerID
select s;
return res.ToList();
}
You can find a whole bunch of Linq examples in visual studio.
Just select Help -> Samples
, and then unzip the Linq samples.
Open the linq samples solution and open the LinqSamples.cs of the SampleQueries project.
The answer you are looking for is in method Linq14:
int[] numbersA = { 0, 2, 4, 5, 6, 8, 9 };
int[] numbersB = { 1, 3, 5, 7, 8 };
var pairs =
from a in numbersA
from b in numbersB
where a < b
select new {a, b};
Not 100% sure about the relationship between these two entities but here goes:
IList<Splitting> res = (from s in [data source]
where s.Customer.CompanyID == [companyID] &&
s.CustomerID == [customerID]
select s).ToList();
IList<Splitting> res = [data source].Splittings.Where(
x => x.Customer.CompanyID == [companyID] &&
x.CustomerID == [customerID]).ToList();
Source: Stackoverflow.com