无法将System.Guid类型转换为int(ASP MVC身份验证)

时间:2015-04-09 13:53:15

标签: c# asp.net .net entity-framework asp.net-mvc-4

我正在尝试在我的数据库中插入数据进行注册,以下是我在AccountController中的内容

    [HttpPost]
    [ValidateAntiForgeryToken]
    public ActionResult Register(PersonLogin rd)
    {
        EBYSContext db = new EBYSContext();
        if (ModelState.IsValid)
        {
            var kisi = new Person();
            kisi.Adi = "Abdullah";
            kisi.TcKimlikNo = "99565282133";
            kisi.Soyadi = "Taher";
            db.Persons.Add(kisi);
            db.SaveChanges();


            WebSecurity.CreateUserAndAccount(rd.Username, rd.Password, new
            {

                //KisiID = new PersonLogin(),  
                Username = rd.Username,
                Password = rd.Password,
                Email = rd.Email,
                YanlisGirisSayisi = 1,
                SifreDegistirilsin = false,
                SonKullanimTarihi = new DateTime(2014, 1, 18),
                SonGirisTarihi = new DateTime(2014, 1, 18),
                SonSifreDegisimTarihi = new DateTime(2014, 1, 18),

            });

            return RedirectToAction("Login","Account");
        }

        ModelState.AddModelError("","Please check your credentials...");
        return View(rd);
    }

我有两个表Person和PersonLogin。后者包含登录信息,如NumberOfLoginAttempts(YanlisGirisSayisi)等。这两个表有1-1关系。

当我发布表单时,我可以在Person表中插入数据,但后来我得到Cannot convert type 'System.Guid' to 'int',错误指向

WebSecurity.CreateUserAndAccount(rd.Username, rd.Password, new
{

经过长时间的研究后,我意识到WebSecurity.InitializeDatabaseConnection中userIdColumn的数据必须是integer。我在数据库中将我的userId(kisiID)列声明为uniqueIdentifier。据我所知,无法将System.Guid转换为int我的问题是如何使用在Person表中创建的相同ID在PersonLogin表中插入新行。

我知道这个问题有点令人困惑,但我希望我能得到一些有用的东西。顺便说一句,我正在使用实体框架数据库第一方法。

Additonal Links: InitializeDatabaseConnection Method

0 个答案:

没有答案