I have to below 2 LINQ statements. They both return (seemingly) the same result set. Can anyone explain to me why I should use one way versus the other? Is it as simple as "You say potato, I say potato; you say tomato, I say tomato"?
Here are the two flavors of LINQ -->
1) The two lets
below are to private Methods that take an ID and return the NAME.
var business = from businesse in context.tblBusinesses
where businesse.BusinessID == businessID
join addresse in context.tblAddresses on businesse.BusinessID equals addresse.BusinessID
let stateName = GetStateNameByID(addresse.StateID)
let countyName = GetCountyNameByID(addresse.CountyID)
select new
{
businesse.BusinessName,
businesse.ContactName,
businesse.EmailAddress,
addresse.AddressLine1,
addresse.AddressLine2,
addresse.AddressLine3,
addresse.CityName,
State = stateName,
addresse.ZipCode,
addresse.ZipPlus,
County = countyName
};
2)
var query = from businesse in context.tblBusinesses
where businesse.BusinessID == businessID
select new
{
businesse.BusinessName,
businesse.ContactName,
businesse.EmailAddress,
Address = from addresse in businesse.tblAddresses
select new
{
addresse.AddressLine1,
addresse.AddressLine2,
addresse.AddressLine3,
addresse.CityName,
State = addresse.StateID,
addresse.ZipCode,
addresse.ZipPlus,
County = addresse.tblAdminCounty
}
};