我需要将 sql 语句转换为 linq 查询。
下面的代码标记了我的问题区域 -
public class MyObjectController : Controller
{
private EFDbContext db = new EFDbContext();
private IObjectRepository objRepo;
public MyObjectController(IObjectRepository objectRepository)
{
objRepo = objectRepository;
}
//
// GET: /Client/MyObject/
public ActionResult Index()
{
if (User.Identity.IsAuthenticated)
{
MembershipUser currentUser = Membership.GetUser(User.Identity.Name, true);
if (currentUser != null && currentUser.ProviderUserKey != null && currentUser.IsApproved)
{
var currentUserId = (Guid)currentUser.ProviderUserKey;
<========HOW TO EXECUTE IN LINQ==================>
Object result = (from obj in objRepo
where obj.ObjId == currentUserId
select obj).FirstOrDefault();
<========HOW TO EXECUTE IN LINQ==================>
return View(result);
}
}
return View();
}
只是为了澄清一下-我想要更像这样的东西,但我不知道如何正确使用语法:
Object myObj = moveRepo.Objects
.Where(m => m.ObjectId)
.Equals(m => currentUserId)
return View(myObj);