在运行Seed方法或抛出任何异常时,是否可以在包管理器控制台中显示用户定义的消息?
当我从Packager管理器控制台运行Seed方法时抛出异常,当我从包管理器控制台收到以下错误消息时,我的运行Seed方法已停止,无法处理其他种子方法!所以我使用Try-Catch块跳过这些异常并继续其他种子方法。
未将对象引用设置为对象的实例。
我的种子方法看起来像这样:
context.Subjects.AddOrUpdate(MyRepository.SeedSubject.Subject());
BookTypes
context.BookTypes.AddOrUpdate(b => b.Type,
new BookType { Type = "Audio" },
new BookType { Type = "Book" },
new BookType { Type = "Video" }
);
图书
context.Books.AddOrUpdate(FCA.Repository.SeedBook.Books());
try
{
context.BookSubjects.AddOrUpdate(b => b.BookSubjectID,
new BookSubject { SubjectID = context.Subjects.SingleOrDefault(s => s.Name == "Graduation").SubjectID, BookID = context.Books.SingleOrDefault(b => b.Title == "Graduation Event").BookID },
new BookSubject { SubjectID = context.Subjects.SingleOrDefault(s => s.Name == "Online Courses").SubjectID, BookID = context.Books.SingleOrDefault(b => b.Title == "3rd Grade Online Complete Set").BookID },
new BookSubject { SubjectID = context.Subjects.SingleOrDefault(s => s.Name == "8th Grade").SubjectID, BookID = context.Books.SingleOrDefault(b => b.Title == "Access 2000 Set Lifepac").BookID });
}
catch (Exception ex)
{
//How to display this message in Package Manager Console while running Seed method?
}
如何在包管理器控制台中显示用户定义的消息?或者这可以使用Break-Point运行Seed方法吗?