它是因爲我已經使用實體框架的同時,和我跳回到與EF 5,但不會此查詢:string.IsNullOrEmpty +實體框架5
SELECT
c.OrganizationName as CompanyName,
c.OrganizationKey as CompanyId,
ISNULL(a.Line1, '') as Line1,
ISNULL(a.Line2, '') as Line2,
a._CityStateZip as CityStateZip
FROM Organizations c
JOIN Addresses a ON c.AddressKey = a.AddressKey
WHERE c.OrganizationName LIKE @term + '%'
AND c.IsSuspended = 0
AND c.IsActive = 1
相同如:
var results = (from c in adms.Organizations
where c.OrganizationName.StartsWith(term)
where !c.IsSuspended
where c.IsActive
select new
{
CompanyName = c.OrganizationName,
CompanyId = c.OrganizationKey,
Line1 = (string.IsNullOrEmpty(c.Address.Line1) ? string.Empty : c.Address.Line1),
Line2 = (string.IsNullOrEmpty(c.Address.Line2) ? string.Empty : c.Address.Line2),
CityStateZip = c.Address._CityStateZip
}).ToList();
當我運行的LINQ to SQL代碼,我得到以下錯誤:
Could not translate expression
'Table(Organization).Where(c => c.OrganizationName
.StartsWith(Invoke(value(System.Func`1[System.String]))))
.Where(c => Not(c.IsSuspended))
.Where(c => c.IsActive)
.Select(c => new <>f__AnonymousType2`5(
CompanyName = c.OrganizationName,
CompanyId = c.OrganizationKey,
Line1 = IIF(IsNullOrEmpty(c.Address.Line1),
Invoke(value(System.Func`1[System.String])), c.Address.Line1),
Line2 = IIF(IsNullOrEmpty(c.Address.Line2),
Invoke(value(System.Func`1[System.String])), c.Address.Line2),
CityStateZip = c.Address._CityStateZip))'
into SQL and could not treat it as a local expression.
難道我完全失去了一些東西,他回覆?我以爲我可以使用LINQ to SQL的string.IsNullOrEmpty。
EF LINQ支持只是很傷心...... LINQ to SQL支持這個(還有更多)。 – usr