如何在多个db表中发送数据?

时间:2015-11-10 12:29:57

标签: asp.net-mvc-4 asp.net-identity asp.net-identity-2

我创建了一个web api 2项目,它创建了一个本地数据库,其中有一个表“AspNetUser”。我已经将这些表与我自己的数据库合并。在我的数据库中,我有一个表“员工信息”,它将存储员工的所有信息,但电子邮件,密码和用户名除外,所有其他信息将存储在“员工信息”表中。

这是注册用户的预先编写的代码:

[AllowAnonymous]
        [Route("Register")]
        public async Task<IHttpActionResult> Register(RegisterBindingModel model)
        {

            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            var user = new ApplicationUser() { UserName = model.UserName, Email = model.Email};

            IdentityResult result = await UserManager.CreateAsync(user, model.Password);

            if (result.Succeeded)
            {
                var currentUser = UserManager.FindByName(user.UserName);

                var roleresult = UserManager.AddToRole(currentUser.Id, model.SelectedRole);


            }
            else if (!result.Succeeded)
            {
                return GetErrorResult(result);
            }

            return Ok();
        }

这是我自己注册用户的逻辑:

 [ResponseType(typeof(EmployeeInformation))]
        [ActionName("EmployeeInfo")]
        [DeflateCompression]
        public IHttpActionResult PostEmployeeInformation(EmployeeInformation EmployeeInfo)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            db.EmployeeInformations.Add(EmployeeInfo);
            db.SaveChanges();

那么如何在“AspNetUser”表中存储电子邮件,密码和用户名以及“EmployeeInformation”表中的所有其他信息(名称,父名,dob等)。 感谢。

1 个答案:

答案 0 :(得分:0)

只需添加git branch --list 'o*' | sed 's/^* //' | xargs -r git branch -d ApplicationUser个实体之间的关系:

EmployeeInformation

public class ApplicationUser: IdentityUser { // other properties public int EmployeeInformationID {get;set;} public virtual EmployeeInformation EmployeeInformation {get;set;} }

执行相同操作
EmployeeInformation

现在你已经为用户的额外信息分类了,例如你可以写:

public class EmployeeInformation
{
    // other properties

    public string UserID {get;set;}
    public virtual ApplicationUser User {get;set;}
}