2017-07-27 133 views
0

我試圖建立一個本地SQL數據庫與下面的遷移,但我得到的錯誤:錯誤號:102,狀態:1,等級:15附近有語法錯誤「」

102,State:1,Class:15 Incorrect syntax near ','..

我我不知道我正在嘗試的是否可能,如果是的話,我出錯的地方。任何意見讚賞。

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"); 
+1

這裏'更新ProjectTypes SET類別='FOD'其中Id = 1,2',改變'= 1,2'到'IN(1,2)'。 '='後的所有其他更新語句都具有多個值。 –

回答

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可以讓你比較反對的東西

0

問題是一個列表與「Sql(」更新區域SET國家/地區='1'的地方= 1,2,3,4「)行;」你不能有這樣的多個值,你將需要使用SQL In - Sql(「Update Areas SET CountryId ='1'WHERE Id in(1,2,3,4)」);

相關問題