我需要將sql語句轉換爲linq查詢。將Sql語句轉換爲Linq以用於C#,實體框架,MVC3
下面有我的問題區域標記的代碼 -
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);
什麼? **是** LINQ。 –
您是先使用edmx還是代碼? –
我先使用代碼 –