まず、私は新人だと言うことから始めましょう。そうは言っても、私はMVC3 w / EF4.3.1を使用してC#でWebアプリを構築しており、dbfirstアプローチを使用しています。ログオンプロセス中に、アプリ全体で使用されるいくつかのセッション変数を設定したいと思います。
私の問題は、セッション変数に値を読み込む方法がわからないことです。以下は、現在AccountController.csにあるコードです。
[HttpPost]
public ActionResult LogOn(LogOnModel model, string returnUrl)
{
if (ModelState.IsValid)
{
if (Membership.ValidateUser(model.UserName, model.Password))
{
FormsAuthentication.SetAuthCookie(model.UserName,
model.RememberMe);
if (Url.IsLocalUrl(returnUrl)
&& returnUrl.Length > 1
&& returnUrl.StartsWith("/")
&& !returnUrl.StartsWith("//")
&& !returnUrl.StartsWith("/\\"))
{
return Redirect(returnUrl);
}
else
{
return RedirectToAction("Index", "Home");
}
}
else
{
ModelState.AddModelError("",
"The user name or password provided is incorrect.");
}
}
// If we got this far, something failed, redisplay form
return View(model);
}
そして、私が読んだことから、次のように、DbContextを使用して特定のフィールドのプロパティにアクセスしようとしているはずです。
using (var context = new DbContext())
{
var svc100 = context.SVC00100.Where(t =>
t.TECHEMAIL.Contains("model.UserName")
// Read the current value of the Name property
Session["Name"] = context.Entry(svc100).Property(u =>
u.Name).CurrentValue;
}
さて...2番目のコードブロックでDbContext()の代わりに何を使用する必要があるかを判断するにはどうすればよいですか?ドロップダウンを使用して必要なものを選択しようとすると、DbContextフレーズを含むエンティティ(CPLUEntities)に関連するものが何も表示されません。
私が発見したリンクのいくつか: