Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FindAsync with non-primary key value

Tags:

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?

like image 322
Robert Avatar asked Sep 23 '13 16:09

Robert


People also ask

What does FindAsync return?

FindAsync(CancellationToken, Object[]) Asynchronously finds an entity with the given primary key values. If an entity with the given primary key values exists in the context, then it is returned immediately without making a request to the store.

What is find method in MVC?

The Find method takes an array of objects as an argument. When working with composite primary keys, pass the key values separated by commas and in the same order that they are defined in the model.


1 Answers

Assuming you are using Entity Framework 6.0 (prerelease):

var userId = ...; var foos = await db.Foos.Where(x => x.UserId == userId).ToListAsync(); 
like image 185
Stephen Cleary Avatar answered Oct 21 '22 00:10

Stephen Cleary