问题描述
我正在使用code第一个实体框架,一个简单的MVC应用程序。我试图使用内置的用户注册/登录。它为我提供了默认的AccountController和的。
I am making a simple MVC application using code first entity framework. I'm trying to use the built in user registration/login. It provides me the default AccountController and ASP User tables.
我的其他企业为播放器,游戏和比赛:
My other entities are Players, Games, and Tournaments:
public class Player
{
public int Id { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public List<Game> Games { get; set; }
public List<Tournament> Tournaments { get; set; }
}
public class Game
{
public int Id { get; set; }
public string Title { get; set; }
public List<Player> Players { get; set; }
public List<Tournament> Tournaments { get; set; }
}
public class Tournament
{
public int Id { get; set; }
public List<Player> Players { get; set; }
public List<Game> Games { get; set; }
}
EF提供的。
大家谁登录的是一个球员。我希望每个球员都有一个用户名和密码。我应该删除我的播放
表并添加播放器
属性所提供的用户
类和 AspNetUsers
表?或者我应该使用外键创建玩家之间的关系
表和 AspNetUsers
表?
Everyone who logs in is a player. I want each player to have a password and username. Should I remove my Players
table and add the Player
properties to the provided User
class and AspNetUsers
table? Or should I use a foreign-key to create a relationship between the Players
table and the AspNetUsers
table?
是那些选择一种或两种可能/ preferable?
Are either or both of those options possible/preferable?
也只需一张纸条,就会出现在玩家,游戏和竞技类的附加属性;我只是从最基本的开始。
Also just a note, there will be additional properties in the Players, Games, and Tournaments classes; I was just starting with the basics.
非常感谢您的宝贵时间。让我知道,如果我是不清楚,或者如果您需要任何额外的信息。
Thank you very much for your time. Let me know if I am being unclear or if you need any additional information.
编辑:
刚刚发现这一点:http://blogs.msdn.com/b/webdev/archive/2013/10/16/customizing-profile-information-in-asp-net-identity-in-vs-2013-templates.aspx
这表明像我上述的两种方法。什么是增加一个新的UserInfo表与将字段添加到现有的表的优势在哪里?
It shows something like both methods I described above. What is the advantage of adding a new UserInfo table vs. adding fields to the existing table?
推荐答案
我想这个属性添加到播放器表:
I would add this property to the player table:
public virtual ApplicationUser User { get; set; }
其中ApplicationUser是一个由Visual Studio中给出开箱的表。
该ApplicationUser使用的身份,所以当用户创建一个新的球员,拥有的PlayerController的创建操作来设置用户在播放表中的玩家ID的用户ID:
where ApplicationUser is the table that was given out of the box by Visual Studio.The ApplicationUser uses identity so when user creates a new player, have the playerController's Create action to set the user id of the user to the player id in the player table:
var userId = User.Identity.GetUserId();
Player.PlayerId = userId;
这篇关于EF code-第一MVC:我应该将字段添加到默认AspNetUsers表或创建另一个'的UserInfo'表涉及AspNetUsers表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!