VirtoCommerce/vc-module-customer

Replace casting in GetQueryPredicate with as operator

asvishnyakov opened this issue · 0 comments

predicate = predicate.Or(m => m.Name.Contains(criteria.SearchPhrase) || m.Emails.Any(e => e.Address.Contains(criteria.SearchPhrase)));

predicate = predicate.Or(x => (x is ContactDataEntity && ((ContactDataEntity)x).FullName.Contains(criteria.SearchPhrase)));

This code will fail with

Unable to cast the type 'VirtoCommerce.CustomerModule.Data.Model.MemberDataEntity' to type 'VirtoCommerce.CustomerModule.Data.Model.ContactDataEntity'. LINQ to Entities only supports casting EDM primitive or enumeration types

exception because Entity Framework can cast only objects with primitive C# types.

With as operator all is well.

Currently we has not issue with that because indexed search will always be used if SearchPhrase specified.