我在脑海中用POCO类和持久性无知原则开发了我的数据层 . 我的代码是这样的
POCO课
public class Report
{
public int Id { get; set; }
public string Name { get; set; }
...
}
}
存储库接口
public interface IReportRepository
{
IEnumerable<Report> GetAllReports();
Report GetReport(int reportId);
...
}
和实体框架代码的接口实现首先,如
public class EFReportRepository : BaseRepository, IReportRepository
{
public EFReportRepository(string connectionString)
: base(connectionString)
{
}
public IEnumerable<Report> GetAllReports()
{
return DbContext.Reports.Include(r => r.AggregationParameters).Include(r => r.ErrorAttachment).Include(r => r.ExcelAttachment).Include(r => r.XmlAttachment).ToList();
}
public Report GetReport(int reportId)
{
return DbContext.Reports.Include(r => r.AggregationParameters).Include(r => r.ErrorAttachment).
Include(r => r.ExcelAttachment).Include(r => r.XmlAttachment).SingleOrDefault(r => r.Id == reportId);
}
在添加授权(asp.net标识)之前一切正常 .
using Microsoft.AspNet.Identity.EntityFramework;
namespace DataRepository.Models
{
public class MyUser : IdentityUser
{
}
}
现在每个报告都有用户创建此报告
public class Report
{
public int Id { get; set; }
public string Name { get; set; }
...
public MyUser CreatedByUser { get; set; }
public string CreatedByUserId { get; set; }
...
}
}
现在我与实体框架紧密相关,我想省略它,因为IdentityUser类的继承 .
我怎样才能排除这种依赖?我会感谢任何帮助)
Update 现在的问题是创建UserManager对象 .
UserManager需要IUserStore作为输入参数 . 此接口在Microsoft.AspNet.Identity.EntityFramework命名空间中具有实现,称为UserStore,因此我的代码就像这样
manager = new UserManager<MyUser>(new UserStore<MyUser>(MyDbContext)).
但是现在MyUser类不是从IdentityUser继承的,所以这段代码被破坏了(UserStore需要这种类)
1 回答
我用这种方法可以正常工作;