错误号码:102,状态:1,类:15','

时间:2017-07-27 11:59:28

标签: c# sql ef-migrations

我正在尝试使用以下迁移设置本地SQL数据库,但我收到错误:

  

102,状态:1,类:15','..

附近的语法不正确

我不确定我所尝试的是否可能,如果可能,我哪里出错了。任何建议表示赞赏。

public partial class Baseline : DbMigration
{
    public override void Up()
    {
        CreateTable(
            "dbo.Areas",
            c => new
                {
                    Id = c.Int(nullable: false, identity: true),
                    Name = c.String(),
                    CountryId = c.Int(nullable: false),
                })
            .PrimaryKey(t => t.Id)
            .ForeignKey("dbo.Countries", t => t.CountryId, cascadeDelete: false);

        Sql("UPDATE Areas SET Name = 'Cumbria' WHERE Id =1");
        Sql("UPDATE Areas SET Name = 'Merseyside' WHERE Id =2");
        Sql("UPDATE Areas SET Name = 'Suffolk' WHERE Id =3");
        Sql("UPDATE Areas SET Name = 'Wiltshire' WHERE Id =4");
        Sql("UPDATE Areas SET Name = 'Scotland' WHERE Id =5");
        Sql("UPDATE Areas SET Name = 'Wales' WHERE Id =6");

        Sql("Update Areas SET CountryId = '1' WHERE Id =1, 2, 3, 4");
        Sql("Update Areas SET CountryId = '2' WHERE Id =5");
        Sql("Update Areas SET CountryId = '3' WHERE Id =6");

        CreateTable(
            "dbo.Countries",
            c => new
                {
                    Id = c.Int(nullable: false, identity: true),
                    Name = c.String(),
                })
            .PrimaryKey(t => t.Id);

        Sql("Update Countries SET Name = 'England' WHERE Id =1");
        Sql("Update Countries SET Name = 'Scotland' WHERE Id =2");
        Sql("Update Countries SET Name = 'Wales' WHERE Id =3");

        CreateTable(
            "dbo.DutyHolders",
            c => new
                {
                    Id = c.Long(nullable: false, identity: true),
                    dhName = c.String(),
                    dhAddress1 = c.String(),
                    dhAddress2 = c.String(),
                    dhAddress3 = c.String(),
                    dhTown = c.String(),
                    dhPostCode = c.String(),
                    dhCountry = c.String(),
                    dhPhoneNumber = c.String(),
                    dhAddressLine1 = c.String(),
                    dhPriority = c.Long(nullable: false),
                    dhCounty = c.String(),
                    dhEmail = c.String(),
                })
            .PrimaryKey(t => t.Id);

        CreateTable(
            "dbo.Locals",
            c => new
            {
                Id = c.Int(nullable: false, identity: true),
                Name = c.String(),
                AreaId = c.Int(nullable: false),
            })
            .PrimaryKey(t => t.Id)
        .ForeignKey("dbo.Areas", t => t.AreaId, cascadeDelete: false);

        Sql("Update Locals SET Name = '[Carlisle District Council]' WHERE Id =1");
        Sql("Update Locals SET Name = '[Copeland Borough Council]' WHERE Id =2");
        Sql("Update Locals SET Name = '[Eden District Council]' WHERE Id =3");
        Sql("Update Locals SET Name = '[Liverpool Metropolitan District Council]' WHERE Id =4");
        Sql("Update Locals SET Name = '[Sefton Metropolitan District Council]' WHERE Id =5");
        Sql("Update Locals SET Name = '[Ipswich Borough Council]' WHERE Id =6");
        Sql("Update Locals SET Name = '[Waveney District Council]' WHERE Id =7");
        Sql("Update Locals SET Name = '[Swindon Unitary Authority]' WHERE Id =8");
        Sql("Update Locals SET Name = 'Wiltshire' WHERE Id =9");
        Sql("Update Locals SET Name = '[Highland Unitary Authority]' WHERE Id =10");
        Sql("Update Locals SET Name = '[Stirling Unitary Authority]' WHERE Id =11");
        Sql("Update Locals SET Name = '[Cardiff Unitary Authority]' WHERE Id =12");
        Sql("Update Locals SET Name = '[Swansea Unitary Authority]' WHERE Id =13");

        Sql("Update Countries SET AreaId = '1' WHERE Id =1, 2, 3");
        Sql("Update Countries SET AreaId = '2' WHERE Id =4, 5");
        Sql("Update Countries SET AreaId = '3' WHERE Id =6, 7");
        Sql("Update Countries SET AreaId = '4' WHERE Id =8, 9");
        Sql("Update Countries SET AreaId = '5' WHERE Id =10, 11");
        Sql("Update Countries SET AreaId = '6' WHERE Id =12, 13");

        CreateTable(
            "dbo.Notification_Link",
            c => new
            {
                Id = c.Int(nullable: false, identity: true),
                notificationId = c.Int(nullable: false),
                dhId = c.Long(nullable: false),
                roleId = c.Int(nullable: false),
            })
            .PrimaryKey(t => t.Id)
            .ForeignKey("dbo.Notifications", t => t.notificationId, cascadeDelete: false)
            .ForeignKey("dbo.DutyHolders", t => t.dhId, cascadeDelete: false);


        CreateTable(
            "dbo.Notifications",
            c => new
                {
                    Id = c.Int(nullable: false, identity: true),
                    IsNew = c.Boolean(nullable: false),
                    Address1 = c.String(nullable: false),
                    Address2 = c.String(nullable: false),
                    Address3 = c.String(),
                    Town = c.String(nullable: false),
                    County = c.String(),
                    PostCode = c.String(nullable: false),
                    Intial = c.Boolean(nullable: false),
                    Withdrawn = c.Boolean(nullable: false),
                    MultiSite = c.Boolean(nullable: false),
                    CountryId = c.Int(nullable: false),
                    AreaId = c.Int(nullable: false),
                    LocalId = c.Int(nullable: false),
                    Update = c.Boolean(nullable: false),
                    InitialNotificationId = c.String(),
                    Email = c.String(),
                    ProjectTypeId = c.Int(),
                    StartDate = c.DateTime(),
                    DutyHolder = c.String(),
                    CreatedDate = c.DateTime(),
                    ModifiedDate = c.DateTime(),
                    ProjectDescription = c.String(),
                    SubmitFlag = c.Boolean(nullable: false),
                    PeopleOnSite = c.Int(),
                })
            .PrimaryKey(t => t.Id)
            .ForeignKey("dbo.Areas", t => t.AreaId, cascadeDelete: true)
            .ForeignKey("dbo.Countries", t => t.CountryId, cascadeDelete: true)
            .ForeignKey("dbo.Locals", t => t.LocalId, cascadeDelete: true)
            .ForeignKey("dbo.ProjectTypes", t => t.ProjectTypeId)
            .Index(t => t.CountryId)
            .Index(t => t.AreaId)
            .Index(t => t.LocalId)
            .Index(t => t.ProjectTypeId);

        CreateTable(
            "dbo.ProjectTypes",
            c => new
                {
                    Id = c.Int(nullable: false, identity: true),
                    Description = c.String(),
                    Category = c.String(),
                })
            .PrimaryKey(t => t.Id);

        Sql("Update ProjectTypes SET Description = '[Asbestos Work]' WHERE Id =1");
        Sql("Update ProjectTypes SET Description = '[Building Services]' WHERE Id =2");
        Sql("Update ProjectTypes SET Description = '[Other Bridge]' WHERE Id =3");
        Sql("Update ProjectTypes SET Description = '[Track Renewal]' WHERE Id =4");

        Sql("Update ProjectTypes SET Category = 'FOD' WHERE Id =1, 2");
        Sql("Update ProjectTypes SET Category = 'RI' WHERE Id =3, 4");


        CreateTable(
            "dbo.Roles",
            c => new
                {
                    Id = c.Int(nullable: false, identity: true),
                    Name = c.String(),
                })
            .PrimaryKey(t => t.Id);

        Sql("Update Roles SET Name = 'Client' WHERE Id =1");
        Sql("Update Roles SET Name = '[Principal Designer]' WHERE Id =2");
        Sql("Update Roles SET Name = '[Principal Contractor]' WHERE Id =3");
        Sql("Update Roles SET Name = 'Designer' WHERE Id =4");
        Sql("Update Roles SET Name = 'Contractor' WHERE Id =5");

2 个答案:

答案 0 :(得分:3)

您的问题在于查询:

Update Areas SET CountryId = '1' WHERE Id =1, 2, 3, 4

应该是

UPDATE Areas SET CountryId = '1' WHERE Id IN (1, 2, 3, 4)

IN允许您与事物列表进行比较

答案 1 :(得分:0)

问题在于“Sql(”更新区域SET CountryId ='1'WHERE Id = 1,2,3,4“);”你不能有这样的多个值,你需要使用SQL In - Sql(“更新区域SET CountryId ='1'WHERE Id in(1,2,3,4)”);