我正在尝试向UserProfile
模型中的类添加一个新属性
public class UserProfile
{
[Key]
[DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]
public int UserId { get; set; }
public string UserName { get; set; }
[Required]
[DataType(DataType.EmailAddress)]
[Display(Name = "Email Address")]
public string Email { get; set; } \\this is the new property
public virtual IList<Game> Games { get; set; }
}
我正在尝试将它添加到我的Configurations.cs
文件中的种子方法中
private void SeedMembership()
{
WebSecurity.InitializeDatabaseConnection("MafiaContext",
"UserProfile", "UserId", "UserName", autoCreateTables: true);
var roles = (SimpleRoleProvider)Roles.Provider;
var membership = (SimpleMembershipProvider)Membership.Provider;
if (!roles.RoleExists("Administrator"))
{
roles.CreateRole("Administrator");
}
if (membership.GetUser("drew", false) == null)
{
membership.CreateUserAndAccount(
"drew",
"password", false,
new { Email = "myemail@gmail.com" }); \\ this line errors
}
if (!roles.GetRolesForUser("drew").Contains("Administrator"))
{
roles.AddUsersToRoles(new[] { "drew" }, new[] { "Administrator" });
}
}
但是,我收到一个错误:
Error 2 Argument 4: cannot convert from 'AnonymousType#1' to 'System.Collections.Generic.IDictionary<string,object>' C:\Code\Mafia\Mafia.EF\Migrations\Configuration.cs 65 21 Mafia.EF
但我什么都想不出来......我的WebMatrix.WebData
版本是v4.0.30319
有什么想法吗?