我有服务。
scheduler.Start();
IJobDetail job = JobBuilder.Create<ReportJob>()
.WithIdentity("reportJob", "reportGroup")
.Build();
ITrigger trigger = TriggerBuilder.Create()
.WithIdentity("reportTrigger", "reportGroup")
.StartNow()
.WithCronSchedule("0 * * ? * Fri")
.Build();
scheduler.ScheduleJob(job, trigger);
在ReportJob中我有
var repository = new StoreReportRepository();
repository.GenerateReports();
在GenerateReports中我尝试访问DatabaseContext
var db = new DatabaseContext()
我收到错误:
外键'FK_dbo.UserSession_dbo.User_UserId'引用无效 表'dbo.User'。无法创建约束或索引。见前 错误。
构造函数DatabaseContext():
public ObjectContext Context
{
get {
return (this as IObjectContextAdapter).ObjectContext;
}
}
public DatabaseContext()
: base("name=DatabaseContext")
{
this.Context.ContextOptions.LazyLoadingEnabled = true;
}
我做错了什么? 感谢
PS UserSession.cs
public class UserSession
{
[Key]
public Guid Id { get; set; }
public Guid UserId { get; set; }
public DateTime Expiration { get; set; }
}