FindAsync with non-primary key value

asp.net-web-api async-await c# entity-framework-6

Question

public class Foo
{
     public int Id { get; set; }
     public int UserId { get; set; }
}

This appears to be the way to do this asynchronously:

DatabaseContext db = new DatabaseContext();
Foo foo = await db.Foos.FindAsync(fooid);

How does one asynchronously get all of the Foos for a specific user based on UserId's value?

Accepted Answer

Assuming you are using Entity Framework 6.0 (prerelease):

var userId = ...;
var foos = await db.Foos.Where(x => x.UserId == userId).ToListAsync();



Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why