I have a set of data (Firstname, Lastname, Birthday) and I want to fetch from my database all the entries that match a set of these. Is there any way to do this via linq query?
I tried creating a compareclass:
public class CompareClass {
public string Firstname { get; set; }
public string Lastname { get; set; }
public DateTime Birthday { get; set; }
}
And now my query looks like this:
var compareData = new List<CompareClass> {
new CompareClass {
Firstname = "Max",
Lastname = "Power",
Birthday = "2010-11-11"
},
new CompareClass {
Firstname = "Marc",
Lastname = "Power",
Birthday = "2005-06-07"
}
};
var persons = await _context.Person
.Where(p => comparedata.Contains(new CompareClass {
Firstname = p.Firstname,
Lastname = p.Lastname,
Birthday = p.Birthday }))
.Select(p => new SomeOtherClass
{
Name = p.Lastname + " " + p.Firstname,
Birthday = p.Birthday
})
.OrderBy(p => p.Name)
.ToListAsync();
Unfortunately, this results in an error:
System.InvalidOperationException: The LINQ expression '...' could not be translated.
Is there a way to do this in a linq query, without having to query all the Person Data from the database? The table is rather big and I would much rather filter it before getting everything out of the database