.Create()方法,实体框架6的参考是什么 [英] What is the reference for .Create() method, Entity Framework 6
问题描述
亲爱的所有。
我正在尝试从教程中在ASP.Net MVC4中构建用户身份验证。我已经完成了80%的项目,但最后我遇到了一个问题。谷歌搜索了一个小时,我无法得到线索。
我有一个用户控件,如下所示。
Dear All.
I am trying to build a User authentication in ASP.Net MVC4 from a tutorial. I am already done with 80 % of the project but at the end i have faced with a problem. I couldn't get a clue even googling for an hour.
I have a user control just like below.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Security;
using System.Data.EntityModel;
using System.Data.Entity;
using System.Data.EntityClient;
using System.Data.OracleClient;
using System.Data.Objects.SqlClient;
namespace SimplyLogInSystem.Controllers
{
public class UserController : Controller
{
private object sysUser;
//
// GET: /User/
public ActionResult Index()
{
return View();
}
[HttpGet]
public ActionResult LogIn()
{
return View();
}
[HttpPost]
public ActionResult LogIn(Models.UserModel user)
{
if (ModelState.IsValid)
{
if (IsValid(user.Email, user.Password))
{
FormsAuthentication.SetAuthCookie(user.Email, false);
return RedirectToAction("Index", "Home");
}
else
{
ModelState.AddModelError("", "Login data is incorrect.");
}
}
return View(user);
}
[HttpGet]
public ActionResult Registration()
{
return View();
}
[HttpPost]
public ActionResult Registration(Models.UserModel user)
{
if (ModelState.IsValid)
{
using (var db = new MainDbContext())
{
var crypto = new SimpleCrypto.PBKDF2();
var encrpPass = crypto.Compute(user.Password);
var sysUsers = SystemUser.CreateSystemUser(Guid.NewGuid(), user.Email, encrpPass, crypto.Salt);
var sysUser = db.SystemUsers.Create();
db.SaveChanges();
return RedirectToAction ("Index", "Home");
}
}
else
{
ModelState.AddModelError("", "Registration data is incorrect.");
}
return View();
}
我有一个模型和一个视图。
and i have a model and a view for it.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel.DataAnnotations;
namespace SimplyLogInSystem.Models
{
public class UserModel
{
[Required]
[StringLength(50)]
[DataType(DataType.EmailAddress)]
[Display(Name="Email Address:")]
public string Email { get; set; }
[Required]
[DataType(DataType.Password)]
[StringLength(20, MinimumLength = 6)]
[Display(Name = "Password:")]
public string Password { get; set; }
}
}
我面临的问题是当我想要创建时它要求参考.Create()的系统用户,我对此没有任何线索。你是否可以帮助我,因为我是MVC和实体框架的新手?
The problem i am facing is that when i want to create the System User it ask for reference of .Create() which i don't have a clue on that. Can you help me with that as I am new to MVC and entity framework?
推荐答案
这篇关于.Create()方法,实体框架6的参考是什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!