I have the following code:
public static ContactEventValue GetContactEventValue(ContactEventType contactEventType, string programCode, string brandCode) { AdvocacyEntities ent = AdvocacyEntities.GetReadOnlyInstance(); ContactEventValue value = ent.ContactEventValues.SingleOrDefault( x => x.ContactEventTypeID == contactEventType.ContactEventTypeID && x.ProgramCode == programCode && x.BrandCode == brandCode); }
When I call it with the values for brandCode and programCode, I return the expected value from the database. When I make a call, but explicitly setting x.ProgramCode and x.BrandCode to null, I get the expected default value from the database:
ContactEventValue value = ent.ContactEventValues.Single( x => x.ContactEventTypeID == contactEventType.ContactEventTypeID && x.ProgramCode == null && x.BrandCode == null);
However, when I call a method with null for codeCode and brandCode, I return null from the database!
I tried changing value == to .Equals () to answer this problem: Optional optional parameter
So x.BrandCode.Equals (brandCode) replaced x.BrandCode == brandCode and x.ProgramCode.Equals (programCode) replaced x.ProgramCode == programCode, but that still didn't work.
I also tried using the operator, still not working.
This article says that no solution was found, and he / she had to use the stored procedure: EF 4 Query - a problem with several parameters I really don't know, I need to go there.
Any ideas?
source share