I have a 1 to Many relationship between tblBusiness
and tblPhone
. For a specific BusinessID
I am trying to return a single string of information to bind to a textbox. Below is my latest attempt along with the Generated SQL from that same LINQ. No matter WHAT I have tried it returns NULL
unless there is a value for all 3 fields.
What am I doing wrong? Thanks!
First the LINQ:
using (var context = ConnectDataContext.Create())
{
context.Log = Console.Out;
var business = from businesse in context.tblBusinesses
where businesse.BusinessID == businessID
select businesse.BusinessName
+ businesse.ContactName
+ businesse.tblPhones.Select(p=>p.PhoneNumber)
.FirstOrDefault()
?? string.Empty;
return business.Single();
}
Now the SQL:
SELECT [t2].[value]
FROM (
SELECT COALESCE(([t0].[BusinessName] + [t0].[ContactName]) + ((
SELECT TOP (1) [t1].[PhoneNumber]
FROM [dbo].[tblPhone] AS [t1]
WHERE [t1].[BusinessID] = [t0].[BusinessID]
)),@p0) AS [value], [t0].[BusinessID]
FROM [dbo].[tblBusiness] AS [t0]
) AS [t2]
WHERE [t2].[BusinessID] = @p1
-- @p0: Input NVarChar (Size = 1; Prec = 0; Scale = 0) [ ]
-- @p1: Input Int (Size = 0; Prec = 0; Scale = 0) [118]