I have entities in the DB which each contain a list of key value pairs as metadata. I want to return a list of object by matching on specified items in the metadata.
Ie if objects can have metadata of KeyOne, KeyTwo and KeyThree, I want to be able to say "Bring me back all objects where KeyOne contains "abc" and KeyThree contains "de"
This is my C# query
var objects = repository.GetObjects().Where(t =>
request.SearchFilters.All(f =>
t.ObjectChild.Any(tt =>
tt.MetaDataPairs.Any(md =>
md.Key.ToLower() == f.Key.ToLower() && md.Value.ToLower().Contains(f.Value.ToLower())
)
)
)
).ToList();
and this is my request class
[DataContract]
public class FindObjectRequest
{
[DataMember]
public IDictionary<string, string> SearchFilters { get; set; }
}
And lastly my Metadata POCO
[Table("MetaDataPair")]
public class DbMetaDataPair : IEntityComparable<DbMetaDataPair>
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public long Id { get; set; }
[Required]
public string Key { get; set; }
public string Value { get; set; }
}
The error I get is
Error was Unable to create a constant value of type 'System.Collections.Generic.KeyValuePair`2[[System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]'. Only primitive types or enumeration types are supported in this context.
KeyValuePair<string, string>before the query has been executed. Can you find the code that does that and post it? - Michael CoxonAny()withf. Savef.Keyandf.Valueto local variables before using them - Michael CoxonToLower()calls are superfluous. - Erik Philips