今天臨睡前突然腦抽把FreeSql 的自動遷移功能給打開了~ 當時想着是不能開的,但忘了刪除掉代碼~
後面又去搞其它代碼的問題,結果弄完忘記刪除啓用遷移代碼了。。
跑一遍之後就發現一些莫名其妙的報錯
看看日誌一堆的字段無效信息。。
列名 'ContentType' 無效。 列名 'Owner' 無效。
這時候纔想起來剛纔的自動遷移沒關。。然後看了下 CotentItemIndex 表被刪了好幾個字段~~
萬幸的是,OC所有內容項都在Content表中有完整數據,搗鼓半天SQL JSON解析+轉換,終於起來了,
下面代碼留在這裏或許某天能節省倆小時~
SELECT [Id] , json_value([Content],'$.ContentItemId') ContentItemId , json_value([Content],'$.ContentType') ContentType , CONVERT(datetime,SUBSTRING( REPLACE(json_value([Content],'$.ModifiedUtc') ,'T',' '),0,20))ModifiedUtc , CONVERT(datetime,SUBSTRING( REPLACE(json_value([Content],'$.PublishedUtc') ,'T',' '),0,20))PublishedUtc , CONVERT(datetime,SUBSTRING( REPLACE(json_value([Content],'$.CreatedUtc') ,'T',' '),0,20))CreatedUtc , json_value([Content],'$.Owner') Owner , json_value([Content],'$.Author') Author , json_value([Content],'$.Published') Published , json_value([Content],'$.Latest') Latest into #temp FROM [dbo].[Document] where Type='OrchardCore.ContentManagement.ContentItem, OrchardCore.ContentManagement.Abstractions' and( json_value([Content],'$.Published') ='true' or json_value([Content],'$.Latest') ='true') and id in ( select DocumentId from ContentItemIndex ) select * from #temp update a set ContentType=b.ContentType,ModifiedUtc=b.ModifiedUtc,PublishedUtc=b.PublishedUtc,CreatedUtc=b.CreatedUtc,Owner=b.Owner,Author=b.Author from ContentItemIndex a inner join #temp b on a.DocumentId=b.Id drop table #temp