2017-06-23 15 views
-2

エラー:System.ArgumentExceptionが発生しました HResult = 0x80070057 メッセージ=オブジェクト型からマッピングが存在しませんSystem.Collections.Generic.List`1 [[System.Object、 mscorlib、バージョン= 4.0.0.0、Culture =ニュートラル、PublicKeyToken = b77a5c561934e089]]を既知のマネージプロバイダのネイティブタイプに変換します。 ソース= のStackTrace: オブジェクト型からマッピングが存在しませんSystem.collections.Generic.List

public class PatInsuListItem : ErrorInfo 
{ 
    public int Insuspan_I { get; set; } 
    public int Insu_Id { get; set; } 
    public string Date_From { get; set; } 
    public string Date_To { get; set; } 
    public string Group_Name { get; set; } 
    public string Short_Name { get; set; } 
    public string Note { get; set; } 
    public string Plan_Name { get; set; } 
    public string Insur_num { get; set; } 
    public string Touch_Date { get; set; } 
    public string Touch_By { get; set; } 
    public string InsuranceRankdescr { get; set; } 
    public string COBFlag { get; set; } 
    public string InsStatus { get; set; } 
    public int Alert { get; set; } 
    public string EndProcessIndicator { get; set; } 
    public string LinkedAuthFlag { get; set; } 
} 

public class PatEFInsuList : ErrorInfo 
{ 
    public PatEFInsuList() { 
     list = new List<PatInsuListItem>(); 
    } 
    public List<PatInsuListItem> list ; 
    public int Count { get; set; } 
} 

するvar _patlist =新しいPatEFInsuList();

 SqlParameter _count = new SqlParameter("@count", SqlDbType.Int) { Direction = System.Data.ParameterDirection.Output }; 

     IList<object> _paramList = new List<object>(); 
     _paramList.Add(new SqlParameter("@patientId", SqlDbType.Int) { Value = parms.PatientId }); 
     _paramList.Add(new SqlParameter("@orderBy", SqlDbType.VarChar) { Value = parms.OrderBy }); 
     _paramList.Add(new SqlParameter("@pageSize", SqlDbType.Int) { Value = parms.PageSize }); 
     _paramList.Add(new SqlParameter("@pageIndex", SqlDbType.Int) { Value = parms.PageIndex }); 
     _paramList.Add(new SqlParameter("@disallowedInsu", SqlDbType.VarChar) { Value = parms.DisallowedInsu }); 
     _paramList.Add(new SqlParameter("@initialId", SqlDbType.Int) { Value = parms.InitialId }); 
     _paramList.Add(new SqlParameter("@initialCOBFlag", SqlDbType.Bit) { Value = parms.InitialCOBFlag }); 
     _paramList.Add(_count); 

     var _result = this.RepositoryContext.Database.SqlQuery<PatInsuListItem>("exec dbo.imc_Patient_RetrieveInsuranceCOBList @patientId, @orderBy, @pageSize, @pageIndex, @disallowedInsu, @initialId, @initialCOBFlag, @count OUT", _paramList); 

     _patlist.Count = _count.Value == null ? 0 : (int)_count.Value; 
     _patlist.list = _result.Select(t => new PatInsuListItem 
     { 
      Insuspan_I = t.Insuspan_I, 
      Insu_Id = t.Insu_Id, 
      Date_From = t.Date_From, 
      Date_To = t.Date_To, 
      Group_Name = t.Group_Name, 
      Short_Name = t.Short_Name, 
      Note = t.Note, 
      Plan_Name = t.Plan_Name, 
      Insur_num = t.Insur_num, 
      Touch_Date = t.Touch_Date, 
      Touch_By = t.Touch_By, 
      InsuranceRankdescr = t.InsuranceRankdescr, 
      COBFlag = t.COBFlag, 
      InsStatus = t.InsStatus, 
      Alert = t.Alert, 
      EndProcessIndicator = t.EndProcessIndicator, 
      LinkedAuthFlag = t.LinkedAuthFlag 
     }).ToList(); 

     return _patlist; 

ランタイム中に 'ToList'行にエラーが発生しています。コードはokをコンパイルします。モデルにはリストがあるので、エラーが起こっている理由はわかりません。

+0

の可能性のある重複https://stackoverflow.com/questions/9149919/no-mapping-exists-from-object-type-system-collections-generic-list-when-executin – user5226582

+0

[EF 4.3のパラメータを持つストアドプロシージャを実行すると、オブジェクト型System.Collections.Generic.Listからマッピングが存在しません](https://stackoverflow.com/questions/9149919/no-mapping-exists-from- object -type-system-collections-generic-list-when-executin) –

答えて

0

あなたの問題はここにある:

IList<object> _paramList = new List<object>(); 

あなたが代わりにこれを試してみてくださいList<object>

に渡すことはできません:あなたは代わりに呼び出すことができます

var _result = this.RepositoryContext.Database.SqlQuery<PatInsuListItem>("exec dbo.imc_Patient_RetrieveInsuranceCOBList @patientId, @orderBy, @pageSize, @pageIndex, @disallowedInsu, @initialId, @initialCOBFlag, @count OUT", 
     new SqlParameter("@patientId", SqlDbType.Int) { Value = parms.PatientId }, 
     new SqlParameter("@orderBy", SqlDbType.VarChar) { Value = parms.OrderBy }, 
     new SqlParameter("@pageSize", SqlDbType.Int) { Value = parms.PageSize }, 
     new SqlParameter("@pageIndex", SqlDbType.Int) { Value = parms.PageIndex }, 
     new SqlParameter("@disallowedInsu", SqlDbType.VarChar) { Value = parms.DisallowedInsu }, 
     new SqlParameter("@initialId", SqlDbType.Int) { Value = parms.InitialId }, 
     new SqlParameter("@initialCOBFlag", SqlDbType.Bit) { Value = parms.InitialCOBFlag }, 
     new SqlParameter("@count", SqlDbType.Int) { Value = _count } //this one you attempted to pass in just the int, not a SqlParameter 
    ); 

OR

を以前_paramListの:

var _result = this.RepositoryContext.Database.SqlQuery<PatInsuListItem>("exec dbo.imc_Patient_RetrieveInsuranceCOBList @patientId, @orderBy, @pageSize, @pageIndex, @disallowedInsu, @initialId, @initialCOBFlag, @count OUT", 
       _paramList.ToArray()); 
+0

甘いです。私はあなたの第二の選択肢を使用し、私はその問題を過ぎた。今私の日付フィールドに問題があります。 'マテリアライズド' System.DateTime 'タイプから' System.String 'タイプへのキャストは無効です' –

+0

あなたの元の投稿とは別の問題です – Alex

+0

はい..私のクラスは文字列を持っていることが分かりました。日時を返します。これはその後修正されています。ありがとう。 –

関連する問題