Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/csharp-4.0/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/ms-access/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net mvc 3 此版本的SQL Server不支持没有聚集索引的表_Asp.net Mvc 3_C# 4.0_Azure_Entity Framework 4.1_Azure Sql Database - Fatal编程技术网

Asp.net mvc 3 此版本的SQL Server不支持没有聚集索引的表

Asp.net mvc 3 此版本的SQL Server不支持没有聚集索引的表,asp.net-mvc-3,c#-4.0,azure,entity-framework-4.1,azure-sql-database,Asp.net Mvc 3,C# 4.0,Azure,Entity Framework 4.1,Azure Sql Database,我正在使用SQL server数据库开发VS2010和EF4.1。 下面提到的代码可以与本地SQLServerDB(SQL2008)配合使用 但是当我为windowsazurecloud和sqlazure发布MVC应用程序时,它给出了下面提到的错误 为什么此错误仅返回SQL Azure(使用桌面SQL server 2008) 如何摆脱这个 My repository代码示例如下所示。调用 Catalog.SaveChanges()方法 using (var catalog = new Data

我正在使用SQL server数据库开发VS2010和EF4.1。 下面提到的代码可以与本地SQLServerDB(SQL2008)配合使用

但是当我为windowsazurecloudsqlazure发布MVC应用程序时,它给出了下面提到的错误

  • 为什么此错误仅返回SQL Azure(使用桌面SQL server 2008)
  • 如何摆脱这个
  • My repository代码示例如下所示。调用 Catalog.SaveChanges()方法

    using (var catalog = new DataCatalog())
    {
        var retailSaleReturn = new RetailSaleReturn
        {
            ReturnQuantity = returnQuantity,
            Product = saleDetailObj.Product,
            Owner = owner,
            Provider = provider,
        };
    
        //add to context
        Catalog.RetailSaleReturns.Add(retailSaleReturn);
    
        //save for db
        Catalog.SaveChanges();
    }
    
    DbUpdateException如下所示:

    {"An error occurred while saving entities that do not expose foreign key properties for their relationships. The EntityEntries property will return null because a single entity cannot be identified as the source of the exception. Handling of exceptions while saving can be made easier by exposing foreign key properties in your entity types. See the InnerException for details."}
    
    {"Tables without a clustered index are not supported in this version of SQL Server. Please create a clustered index and try again."}
    
    InnerException如下所示:

    {"An error occurred while saving entities that do not expose foreign key properties for their relationships. The EntityEntries property will return null because a single entity cannot be identified as the source of the exception. Handling of exceptions while saving can be made easier by exposing foreign key properties in your entity types. See the InnerException for details."}
    
    {"Tables without a clustered index are not supported in this version of SQL Server. Please create a clustered index and try again."}
    
    StackTrace如下所示

    at System.Data.Entity.Internal.InternalContext.SaveChanges()
       at PawLoyalty.Data.Repositories.CustomersRepository.ReturnRetailOnlySales(Guid saleDetailId, Int32 returnQuantity, String providerKey, String ownerKey) in D:\PawLoyalty Module\PawLoyalty\PawLoyalty\PawLoyalty.Data\Repositories\CustomersRepository.cs:line 550
       at PawLoyalty.Web.Areas.Providers.Controllers.CustomersController.ReturnRetailOnlySales(String providerKey, String ownerKey, String petKey, Guid saleDetailId, Int32 returnQuantity) in D:\PawLoyalty Module\PawLoyalty\PawLoyalty\PawLoyalty.Web\Areas\Providers\Controllers\CustomersController.cs:line 942
       at lambda_method(Closure , ControllerBase , Object[] )
       at System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters)
       at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters)
       at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClassd.<InvokeActionMethodWithFilters>b__a()
       at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation)
    
    at System.Data.Entity.Internal.InternalContext.SaveChanges()
    在D:\PawLoyalty模块\PawLoyalty\PawLoyalty\PawLoyalty\PawLoyalty.Data\Repositories\CustomerRepository.ReturnRetailOnlySales(Guid saleDetailId,Int32 returnQuantity,String providerKey,String ownerKey)中的PawLoyalty.Data\Repositories\CustomerRepository.cs:第550行
    在D:\PawLoyalty Module\PawLoyalty\PawLoyalty\PawLoyalty\PawLoyalty.Web\Areas\Controllers.CustomerController.ReturnRetailOnlySales(字符串providerKey、字符串ownerKey、字符串petKey、Guid saleDetailId、Int32 returnQuantity)中的D:\PawLoyalty模块\PawLoyalty\PawLoyalty.Web\Areas\Providers\Controllers\
    在lambda_方法中(闭包、控制器基、对象[])
    位于System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext ControllerContext,IDictionary`2参数)
    位于System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext ControllerContext,ActionDescriptor ActionDescriptor,IDictionary`2参数)
    在System.Web.Mvc.ControllerActionInvoker.c_uudisplayClassD.b_uua()中
    位于System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter筛选器、ActionExecutingContext预文本、Func`1 continuation)
    
    您需要在SQL Azure中要向其添加行的所有表上创建聚集索引;否则,insert语句总是失败

    在TableName(yourGUIDColumn)上创建唯一的聚集索引Idx\u TableName

    以下是关于这些指数的一般指南和限制的参考:


    这里有另一篇文章解释了这背后的原因:

    我发现升级到v12更容易

    我必须备份(因为我很聪明!),然后将我所有的数据库(使用旧的控制台manage.windowszaure.com)从Web升级到基本层。然后按照此处的说明升级()

    简言之:

    • openportal.azure.com
    • 选择Sqlserver
    • 操作
    • 最新SQL数据库更新
    要使用azure powershell监视进度,请执行以下操作:

    Add-AzureAccount
    Switch-AzureMode -Name AzureResourceManager
    Get-AzureSqlServer -ServerName '<<yoursqlservername>>' -ResourceGroupName '<<sqlserverresourcegroupname>>'
    
    添加AzureAccount
    切换AzureMode-名称AzureResourceManager
    获取AzureSqlServer-服务器名“”-资源组名“”
    
    谢谢。当我创建主键时,它会工作。ALTER TABLE[dbo].[RetailSaleReturns]添加主键([Id])还有一点需要记住,您不能在没有索引的表上删除索引。此问题似乎已在SQLServer的更高版本中得到解决。有人知道它是在哪个版本修复的吗?