我试图找出在我更新数据库时导致验证异常的具体验证错误是什么。我有理由确信罪魁祸首是SaveChanges(). 我认为我的 3 个类中的一个或多个中的一个或多个属性有问题。解决异常的唯一方法是发现验证错误。
尽管我对几种不同的语言有经验,但在这种调试方式方面,我还是个新手。我在指示的地方设置了一个断点,所以我可以看到debug.writeline结果,但有两个问题:它永远不会在断点处停止,而且我在输出窗口下拉列表中没有看到“调试”。
我不明白什么?有没有更好的方法来捕获验证错误?
这是 configuration.cs 文件中的完整代码。
namespace AlbumSong2.Migrations
{
using System;
using System.Data.Entity;
using System.Data.Entity.Migrations;
using System.Data.Entity.Validation;
using System.Diagnostics;
using System.Linq;
internal sealed class Configuration : DbMigrationsConfiguration<AlbumSong2.Model.AlbumDbContext>
{
public Configuration()
{
AutomaticMigrationsEnabled = false;
//if (System.Diagnostics.Debugger.IsAttached == false)
// System.Diagnostics.Debugger.Launch();
}
protected override void Seed(AlbumSong2.Model.AlbumDbContext context)
{
// This method will be called after migrating to the latest version.
// You can use the DbSet<T>.AddOrUpdate() helper extension method
// to avoid creating duplicate …Run Code Online (Sandbox Code Playgroud)