c# - 具有非主键值的 FindAsync

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

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

这似乎是异步执行此操作的方法:

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

如何根据 UserId 的值异步获取特定用户的所有 Foos?

最佳答案

假设您使用的是 Entity Framework 6.0(预发行版):

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

关于c# - 具有非主键值的 FindAsync,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18964488/

相关文章:

c# - Visual Studio 2012 与 Visual Studio 2010 的比较(增量)

c# - 表达式<Func<T, bool 值>> VS Func<T, bool 值>

c# - 如何在 C# 中构建具有未指定数量参数的方法

asp.net-mvc - 部署到 azure 时向 Controller 发出请求会引发 500 内部错误

c# - 大开关的替代品?

asp.net-web-api - 将对象作为参数传递给 Breeze Controller 操作

c# - 一个站点上没有 'Access-Control-Allow-Origin' header ,但另一个站点上没有

c# - 等待异步方法而不阻塞线程

c# 异步方法中的阻塞代码

c# - ASP.NET Core 同步和异步 Controller 操作之间没有太大区别