2016-04-23 15 views
1

我幾乎只是將我的Web Api項目部署到免費的Azure服務器上,並且上面有一個基本的DB。在我將它發佈到網站後,它運行得非常好。我可以從我的角度2應用程序調用它並從數據庫接收數據。將實體框架部署到Azure,工作1小時,現在出現錯誤500

2小時後,當我嘗試再次使用它時,當調用有效的REST方法時,我現在收到錯誤500。

當我調試我的角度2應用程序時,我可以在網絡選項卡中看到以下內容。

xhr_backend.ts:82 GET http://sitename.azurewebsites.net/api/getbookings 500 (Internal Server Error) 

也試圖與郵遞員,它也得到那個錯誤,我回來有以下幾種:

{ 
    "Message": "An error has occurred." 
} 

也試圖阻止該網站,並再次啓動它,並沒有幫助。

它必須是Entity框架的東西,因爲該網站正在運行。

我使用的遷移,並已建立了配置文件中的一些測試數據,如:

var pet = new List<Pet> 
     { 
      new Pet {BookingId = 1, PetType = PetType.Dog}, 
      new Pet {BookingId = 2, PetType = PetType.Dog}, 
      new Pet {BookingId = 2, PetType = PetType.Cat}, 
      new Pet {BookingId = 3, PetType = PetType.Dog}, 
      new Pet {BookingId = 4, PetType = PetType.Dog}, 
      new Pet {BookingId = 4, PetType = PetType.Cat}, 
      new Pet {BookingId = 5, PetType = PetType.None}, 
      new Pet {BookingId = 6, PetType = PetType.Cat}, 
      new Pet {BookingId = 6, PetType = PetType.Dog}, 
      new Pet {BookingId = 7, PetType = PetType.None}, 
      new Pet {BookingId = 8, PetType = PetType.None}, 
     }; 

     pet.ForEach(p => context.Pets.AddOrUpdate(s => s.Id, p)); 
     context.SaveChanges(); 

我不知道如何找到這可能是錯在這裏。我第一次將應用程序部署到Azure時:D

是否有任何知道Azure是否多次調用update-database? (當你部署應用程序)

當我嘗試在本地databae進入更新的數據庫,我得到的錯誤:

Sequence contains more than one element 

也許這可能涉及到的?希望有人有一些技巧我可以嘗試。

更新:

經過一番調查後,我打開錯誤的API。試圖用AddOrUpdate與指定標識表達,那裏可能是表達一個以上的匹配時

<ExceptionMessage>Sequence contains more than one element</ExceptionMessage> 
<ExceptionType>System.InvalidOperationException</ExceptionType> 

回答

1

此異常是造成:我現在碰到下面的錯誤。

內部函數將使用SingleOrDefault,如果找到多個匹配元素,則會引發異常。

+0

我正在研究它現在..現在我已經修復了導致問題的AddOrUpdate,現在我試圖再次部署到站點以查看它現在是否可用。 – Mikkel

+0

看看這個http://stackoverflow.com/a/25247848/5233410你可能是正確的,它與AddOrUpdate有關。如果是這樣的話,我會刪除我的答案,因爲那樣會導致你的操作偏離主題。 – Nkosi

+0

是的,它現在正在工作:D它是AddOrUpdate,其間有一些dublicates。你可以編輯或不編輯你的文章,現在工作,所以我很高興;)美好的一天。 – Mikkel

相關問題