在EF Code First中使用AspNetUsers创建实体关系

时间:2016-08-04 18:42:16

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

我在ASP.NET Identity项目中使用MVC,我需要在ASP.NET Identity AspNetUsers实体和我的自定义表之间创建实体关系。众所周知,AspNetUsers表格使用字符串表示 ID 字段,并且此 ID中包含 GUID 场。但是,我不确定以下问题:

1)我应该在自定义类中使用哪种数据类型来创建PK/FK关系? 字符串 GUID

2)如何为每个新记录自动生成此自定义 ID 字段?是否也可以使它sequential以便记录可以排序?

1 个答案:

答案 0 :(得分:1)

1 - 你应该使用<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet"/> HTML : <div class="row" id="empListTable"> <div class="form-group col-md-12" style="padding-left: 35px;"> <div class="col-xs-6 col-sm-3" style="padding-left: 35px;font-weight:bold"> Hired </div> <div class="col-xs-6 col-sm-3"style="padding-left: 25px;font-weight:bold"> Screened </div> <div class="col-xs-6 col-sm-3" style="padding-left: 15px;font-weight:bold"> Pre-Qualified </div> <div class="col-xs-6 col-sm-3" style="padding-left: 25px;font-weight:bold"> Approved </div> </div> <div class="form-group col-md-12" style="padding-left: 35px;"> <div class="col-xs-6 col-sm-3" style="padding-left: 25px;font-size:40px;font-weight:bold"> 10 </div> <div class="col-xs-6 col-sm-3" style="padding-left: 25px;font-size:40px;font-weight:bold"> 10 </div> <div class="col-xs-6 col-sm-3" style="padding-left: 35px;font-size:40px;font-weight:bold"> 6 </div> <div class="col-xs-6 col-sm-3" style="padding-left: 35px;font-size:40px;font-weight:bold"> 2 </div> </div> <div class="form-group col-md-12" style="padding-left: 35px;"> <div class="col-sm-3" style="font-size:12px;color:#888;"> Total Number of <br /> Employees hired </div> <div class="col-sm-3" style="font-size:12px;color:#888"> Employees screened <br /> via phone or web </div> <div class="col-sm-3" style="font-size:12px;color:#888"> Via Screened <br />employees </div> <div class="col-sm-3" style="font-size:12px;color:#888"> Employees have <br />recieved tax credits </div> </div> <div class="form-group col-md-12" style="padding-left: 35px;"> <div class="col-sm-3" style="font-size:8px"> <button type="submit" class="btn btn-primary btn-lg outline" ng-click="">More Info <i class="fa fa-arrow-down"></i></button> </div> <div class="col-sm-3"> <button type="submit" class="btn btn-primary btn-lg outline" ng-click="">More Info <i class="fa fa-arrow-down"></i></button> </div> <div class="col-sm-3"> <button type="submit" class="btn btn-primary btn-lg outline" ng-click="">More Info <i class="fa fa-arrow-down"></i></button> </div> <div class="col-sm-3"> <button type="submit" class="btn btn-primary btn-lg outline" ng-click="">More Info <i class="fa fa-arrow-down"></i></button> </div> </div> 。 (见this

如果您打开string,则会看到edmx中的Id(GUID)为AspNetUser

2 - 您可以在模型中使用构造函数并生成GUID,如下所示:

string

3- 顺序Guid生成器请参阅this。我建议public partial class Student { public Student() { Id = System.Guid.NewGuid().ToString(); } //Other fileds }