2

同じ MVC 3 & C# コードを、2 つの異なる MySql インストールで同じ MySql 5.5 データベースのコピーと共に使用する場合。1つは完全に機能しますが、もう1つは「オブジェクトはIConvertibleを実装する必要があります」というエラーで失敗します。ローカル PC の MySql インストールに対してクエリを実行すると、クエリは常に完全に機能しますが、ローカル PC の Visual Studio 2010 からインターネット サービス プロバイダーの MySql インストールにある同じデータベースのコピーに対してクエリを実行しようとすると、「オブジェクトはIConvertible を実装します。」コードで変更するのは、web.config の ConnectionString のサーバー名だけです。それ以外の場合、コードとデータベースはまったく同じです。注: ISP の MySql インストールに対する他のすべてのクエリは完全に機能しますが、この 1 つの特定のクエリのみが機能しません。

これを数日間トラブルシューティングしようとした後、「オブジェクトはIConvertibleを実装する必要があります」というエラーメッセージは実際に起こっていることとは何の関係もないと確信しており、ISPのMySql構成が何らかの原因である可能性があるという印象も受けていますこの問題には次の理由があります。

  1. これが本当にコード内の「オブジェクトは IConvertible を実装する必要がある」問題である場合、問題はコード内で持続し、どの DB インストールにヒットしても発生します。

  2. ローカル PC の作業コピーから ISP の DB を完全に削除して再作成しましたが、まったく同じエラーが発生します。

  3. 最も興味深いのは、クエリに 3 つのネストされた IEnumerable リストがあり、これらはすべて IEnumerables と同じ方法でセットアップされており、クエリでこれらのネストされたリストのいずれか 1 つをコメントアウトすると、クエリは ISP の DB に対して正常に実行されます。どのネストされたリストがコメントアウトされるかは関係ありません。ネストされたリストが 2 つ以下であり、ISP の DB へのクエリが機能することだけです。これが、ローカル PC の MySql インストールをクエリするときにこの問題が発生しないため、ISP での MySql の構成が何らかの方法でクエリを制限している可能性があるという結論につながります。エラーメッセージは、実際に起こっていることに実際には当てはまらないようです。繰り返しになりますが、ISP の MySql インストールに対する他のすべてのクエリは完全に機能しますが、この特定のクエリに 3? が含まれるネストされた IEnumerable リストが 2 つ以上含まれているクエリはありません。

クエリ エラー「オブジェクトは IConvertible を実装する必要があります」

    Server Error in '/' Application.
    ________________________________________
    Object must implement IConvertible. 
    Description: An unhandled exception occurred during the execution of the current web request.             Please review the stack trace for more information about the error and where it originated in the code. 

    Exception Details: System.InvalidCastException: Object must implement IConvertible.

    Source Error: 

    Line 392:
    Line 393:
    Line 394:            var query =
    Line 395:                  (from p in db.products
    Line 396:                   where p.ClientId == clientId

    Source File: C:\Users\JR\Documents\Visual Studio 2010\Projects\Subversion\ReservarMVC\ReservarMVC\Models\ProductRepository.cs    Line: 394 

    Stack Trace: 

    [InvalidCastException: Object must implement IConvertible.]
    System.Convert.ChangeType(Object value, Type conversionType, IFormatProvider provider) +9528453
    MySql.Data.Entity.EFMySqlDataReader.ChangeType(Object sourceValue, Type targetType) +566
    MySql.Data.Entity.EFMySqlDataReader.GetValue(Int32 ordinal) +231
    System.Data.Common.Internal.Materialization.ErrorHandlingValueReader`1.GetValue(DbDataReader reader, Int32 ordinal) +215
    System.Data.Common.Internal.Materialization.Shaper.GetColumnValueWithErrorHandling(Int32 ordinal) +46
    lambda_method(Closure , Shaper ) +180
    System.Data.Common.Internal.Materialization.Coordinator`1.ReadNextElement(Shaper shaper) +170
    System.Data.Common.Internal.Materialization.RowNestedResultEnumerator.MoveNext() +235
    System.Data.Common.Internal.Materialization.ObjectQueryNestedEnumerator.TryReadToNextElement() +49
    System.Data.Common.Internal.Materialization.ObjectQueryNestedEnumerator.ReadElement() +29
    System.Data.Common.Internal.Materialization.ObjectQueryNestedEnumerator.MoveNext() +68
    System.Collections.Generic.List`1..ctor(IEnumerable`1 collection) +327
    System.Linq.Enumerable.ToList(IEnumerable`1 source) +58
    ReservarMVC.Models.ProductRepository.GetProductList(Nullable`1 dateStart, Nullable`1    dateEnd,         Nullable`1 personQuantityId, Nullable`1 roomQuantityId) in C:\Users\JR\Documents     \Visual      Studio 2010\Projects\Subversion\ReservarMVC\ReservarMVC\Models\ProductRepository.cs:394
    ReservarMVC.Models.ProductRepository.GetProductListSearch(Nullable`1 dateStart, Nullable`1 dateEnd, Nullable`1 personQuantityId, Nullable`1 roomQuantityId) in C:\Users\JR\Documents\Visual Studio 2010\Projects\Subversion\ReservarMVC\ReservarMVC\Models\ProductRepository.cs:605
    ReservarMVC.Controllers.PortalController.MyExcurcion(ProductListSearchVM viewModel) in C:\Users\JR\Documents\Visual Studio 2010\Projects\Subversion\ReservarMVC\ReservarMVC\Controllers\PortalController.cs:63
     lambda_method(Closure , ControllerBase , Object[] ) +162
     System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters) +17
     System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters) +208
      System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +27
      System.Web.Mvc.<>c__DisplayClass15.<InvokeActionMethodWithFilters>b__12() +55
      System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation) +263
      System.Web.Mvc.<>c__DisplayClass17.<InvokeActionMethodWithFilters>b__14() +19
      System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodWithFilters(ControllerContext controllerContext, IList`1 filters, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +191
      System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) +343
      System.Web.Mvc.Controller.ExecuteCore() +116
      System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext) +97
      System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(RequestContext requestContext) +10
      System.Web.Mvc.<>c__DisplayClassb.<BeginProcessRequest>b__5() +37
      System.Web.Mvc.Async.<>c__DisplayClass1.<MakeVoidDelegate>b__0() +21
      System.Web.Mvc.Async.<>c__DisplayClass8`1.<BeginSynchronous>b__7(IAsyncResult _) +12
      System.Web.Mvc.Async.WrappedAsyncResult`1.End() +62
      System.Web.Mvc.<>c__DisplayClasse.<EndProcessRequest>b__d() +50
      System.Web.Mvc.SecurityUtil.<GetCallInAppTrustThunk>b__0(Action f) +7
      System.Web.Mvc.SecurityUtil.ProcessInApplicationTrust(Action action) +22
      System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +60
      System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +9
      System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +8967601
      System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +184

      ________________________________________
      Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.261

LINQ からエンティティへのクエリ:

    public IEnumerable<ProductListVM> GetProductList(DateTime? dateStart, DateTime? dateEnd, int? personQuantityId, int? roomQuantityId)
    {
        var query =
              (from p in db.products
               where p.ClientId == clientId
               where p.ProductTypeId == 5 
               where personQuantityId <= p.Capacity
               where roomQuantityId <= p.Quantity
               select new ProductListVM
               {
                   ProductId = p.ProductId,
                   ClientId = p.ClientId,
                   Name = p.Name_en,
                   Title = p.Title_en,
                   Description = p.Description_en,
                   Quantity = p.Quantity,
                   Capacity = p.Capacity,
                   newbookings = from b in db.bookings 
                                 where b.ProductId == p.ProductId
                                 from res in db.reservations
                                 where b.ReseravationId == res.ReservationId
                                 where b.BookingDateTime >= dateStart && b.BookingDateTime <= dateEnd && res.ReservationStateId != 3 
                                 select new BookingVM
                                 {
                                     ProductId = b.ProductId,
                                     BookingId = b.BookingId,
                                     ClientId = b.ClientId,
                                     ReservationId = b.ReseravationId,
                                     BookingDateTime = b.BookingDateTime
                                 },                  
                   newratecategories = from prc in db.productratecategories
                                       where prc.ProductId == p.ProductId
                                       from rc in db.ratecategories
                                       where prc.RateCategoryId == rc.RateCategoryId
                                       where (dateStart >= rc.DateStart && dateEnd <= rc.DateEnd) || (dateStart >= rc.DateStart || dateEnd <= rc.DateEnd)                                           
                                       select new MegaRateCategoryVM
                                       {
                                           RateCategoryId = rc.RateCategoryId,                                               
                                           DateStart = rc.DateStart,
                                           DateEnd = rc.DateEnd                                      
                                       },
                   newproductimages = (from pi in db.productimages
                                       where pi.ProductId == p.ProductId
                                       from ig in db.imagegalleries
                                       where pi.ImageGalleryId == ig.ImageGalleryId
                                       select new MegaProductImageVM
                                       {
                                           ig_Description = ig.ig_Description,
                                           ImageGalleryId = pi.ImageGalleryId
                                       }).OrderByDescending(i => i.ImageGalleryId)
               }).ToList();

        return query;
    }

商品リストViewModel:

    namespace Project.ViewModels
    {
        [Serializable]
        public class ProductListVM : BaseViewModel
        {        
            public int ProductId { get; set; }        
            public int? ClientId { get; set; }
            public int? ProductTypeId { get; set; }
            public int? ProductStateId { get; set; }
            public String Name { get; set; }        
            public String Title { get; set; }
            public String Description { get; set; }
            public int? Quantity { get; set; }
            public int? Capacity { get; set; }        

            //PRODUCTIMAGE table fields
            public IEnumerable<MegaProductImageVM> newproductimages { get; set; }

            //RATECATEGORY table fields
            public IEnumerable<MegaRateCategoryVM> newratecategories { get; set; }

            //BOOKING table fields
            public IEnumerable<BookingVM> newbookings { get; set; }       

        }

    }

この動作の原因は何ですか? これは、MySql 5.5 のデータベース構成のクエリしきい値設定またはネットワーク設定が原因である可能性がありますか? どちらの MySql 5.5 インストールでもデフォルトを変更していません。標準のMySql Connector/Net 6.5.4を使用して、Microsoftの標準MVC 3、C#、Entity Framework 4、LINQ-to-EntitiesコードとともにDBにアクセスしています。

これに関するヘルプは大歓迎です。ありがとう、Atlas361

4

2 に答える 2

7

これを修正するには、接続文字列に「respect binary flags=false」を追加します。例:

connectionString="metadata=res://*/Something.csdl|res://*/Something.ssdl|
res://*/Something.msl;provider=MySql.Data.MySqlClient;
provider connection string=&quot;server=my-server;User Id=some-user;
Persist Security Info=True;database=some-database;respect binary flags=false&quot;"

これは、MySQL 5.0 および 5.1 の特定のバージョンの既知の問題です。

MySQL が 1 つ以上の列について誤ったメタデータを返す特定の状況があります...アプリケーションに必要な変更が大きすぎる場合は、接続文字列に「respect binary flags=false」を追加すると、コネクタが使用する以前の動作: 文字列としてマークされた列は、バイナリ フラグに関係なく、文字列として返されます。特に BLOB としてマークされている列のみが BLOB として返されます。

これが将来の旅行者に役立つことを願っています。

于 2013-04-11T22:55:25.450 に答える
0

MVCアプリケーションをISPに公開して、インターネット経由でのクエリによって発生する可能性のある問題を排除しましたが、「オブジェクトはIConvertibleを実装する必要があります」という同じエラーが発生しました。これをさらにトラブルシューティングした後、Arvixe.comの完全に不十分なサポートスタッフ彼らがデータベースを持っていたMySqlの実際のバージョンは2008年にリリースされた5.1.54であり、2010年後半にリリースされたMySql 5.5ではないことを発見しました。MySqlドキュメントによると、MySql Connector /Net6.5.4とMicrosoftのEntityFramework4は互換性があります、しかし私はこれが真実ではないことに気づきました。Arvixe.comと戦ってMySql 5.5サーバーに私を置いた後、問題は解決しました。したがって、これは最終的にバージョンの互換性の問題でした。

答えがお役に立てば幸いです。Atlas361

于 2013-01-22T03:19:43.047 に答える