在新的Entity Framework 6.1 beta/pre-release中,它们包含了更改Id数据库中使用的列的数据类型的选项.我正在研究如何实现这一点并得出以下结论:
public class ApplicationUser : IdentityUser<int, IdentityUserLogin<int>,
IdentityUserRole<int>, IdentityUserClaim<int>>, IObjectState
{
}
Run Code Online (Sandbox Code Playgroud)
public class AuthenticationContext : IdentityDbContext<ApplicationUser, IdentityRole<int, IdentityUserRole<int>>, int, IdentityUserLogin<int>, IdentityUserRole<int>, IdentityUserClaim<int>>
{
public AuthenticationContext()
: base("ConnectionString")
{
}
}
Run Code Online (Sandbox Code Playgroud)
public AccountController() : this(new UserManager<ApplicationUser, int>(new UserStore<ApplicationUser, IdentityRole<int, IdentityUserRole<int>>, int, IdentityUserLogin<int>, IdentityUserRole<int>, IdentityUserClaim<int>>(new AuthenticationContext())))
{
}
public AccountController(UserManager<ApplicationUser, int> userManager)
{
UserManager = userManager;
}
public UserManager<ApplicationUser, int> UserManager { get; private set; }
Run Code Online (Sandbox Code Playgroud)
运行应用程序(这是默认的EF/MVC应用程序)时,单击"注册"时会出现以下错误:
EntityFramework.dll中出现"System.InvalidOperationException"类型的异常但未在用户代码中处理其他信息:类型'Microsoft.AspNet.Identity.EntityFramework.IdentityRole2 [System.Int32,Microsoft.AspNet.Identity.EntityFramework.IdentityUserRole1 [System.Int32]]'未映射.使用Ignore方法或NotMappedAttribute数据批注检查未明确排除类型.验证类型是否已定义为类,不是原始类型还是通用类型,并且不从EntityObject继承
显然我做错了什么,但我不确定应该调整什么才能让它发挥作用.有什么建议?
我正在研究基本的MVC5/EF6应用程序,并遇到以下错误:
No parameterless constructor defined for this object.
Run Code Online (Sandbox Code Playgroud)
当我在创建新Controller时使用由Visual Studio 2013搭建的默认创建操作和视图时会发生这种情况.我没有调整那些生成的文件(TestItemController,Views/TestItem/Create.cshtml)中的任何内容.我的控制器是脚手架的实体看起来像这样:
public class TestItem
{
private Category _category;
// Primary key
public int TestItemId { get; set; }
public int CategoryId { get; set; }
public string TestColumn { get; set; }
public virtual Category Category {
get { return _category; }
set { _category = value; }
}
protected TestItem()
{
}
public TestItem(Category category)
{
_category = category;
}
}
public class Category
{ …Run Code Online (Sandbox Code Playgroud) asp.net-mvc domain-driven-design entity-framework ef-code-first