2014-01-08 3 views
1

Compact Framework에서 사용하기 위해 DapperLite (Dapper 포트)을 사용하고 있습니다. 난 ArgumentException, SqlMapper.cs 파일의 지정된 줄에 아래의 방법에 다른 정보가 없습니다..Net Compact에서 PropertyInfo.SetValue()에 대한 ArgumentException

다음에 무엇을 볼지 또는 실제로 손상된 것과 정말 어려움이 있습니다. 그 시점에서

/// <summary> 
    /// Populate a references type from an IDataRecord by matching column names to property names. 
    /// </summary> 
    private static void PopulateClass(object objectClass, IDataRecord reader) 
    { 
     Type theType = objectClass.GetType(); 
     PropertyInfo[] p = theType.GetProperties(); 


     // Only set properties which match column names in the result. 
     foreach (string columnName in GetColumnNames(reader)) 
     { 
      string colName = columnName; 
      object value = reader[colName]; 
      PropertyInfo pi = p.FirstOrDefault(x => x.Name == colName); 


      if (pi == null || value == DBNull.Value) continue; 


      Type columnType = value.GetType(); 
      Type actualType = Nullable.GetUnderlyingType(pi.PropertyType) ?? pi.PropertyType; 


      // Check for a directly assignable type 
      if (actualType == columnType || actualType == typeof(string) || actualType == typeof(int)) 
      { 
       // Error generated here 
       pi.SetValue(objectClass, value, null); 
      } 
      else 
      { 
       value = actualType.GetMethod("Parse", new[] { typeof(string) }).Invoke(null, new[] { value }); 
       pi.SetValue(objectClass, value, null); 
      } 
     } 
    } 

숫자가 objectClass = Models.Employeevalue=1이다. 상기 방법에서 더 위로부터의 colNameEmployee 모델의 intId이다.


의견에 따라

추가 직원 모델 : 나는 그 시점에서 내 Model.Employee 볼 때

namespace BioPadPunchClock.Models 
{ 
    public class Employee 
    { 
     public int Id { get; set; } 
     public int CDB_Employee_PK { get; set; } //Employee PK in the Central DB. If .null., new emp record on this timeclock needs to be pushed to the CDB. 
     public string Name { get; set; } 
     //public string FaceImage { get; set; } //path to Jpeg image 136x90 pixels .\NAND\pictures\ named as <pk>.jpg 
     public DateTime? BirthDate { get; set; } 
     public string Status { get; set; } //Full Time – Hourly, Inactive, Terminated, Part Time - Hourly 
     public DateTime? LastPunch { get; set; } 
     public string LastPunchDirection { get; set; } //IN or OUT 
     public string PIN { get; set; } // 4 digit 
     public int CardNum { get; set; } //HID Card Number 
     public int CardFacCode { get; set; } //HID Card Facility Code 
     public string FpTemplate { get; set; } //Fingerprint Template (registered fingerprint) 
     public DateTime? LastUpdate { get; set; } //When this employee record was last sync’d to the CDB. This value will match exactly in the LDB and CDB after a successful sync. 
     public int DayTotal { get; set; } // Minutes cumulative for the current day at time of last punch 
     public int PayPeriodTotal { get; set; } //Minutes cumulative for the current pay period at time of last punch 
     public string Department { get; set; } 
     public string SSN { get; set; } 
     public bool ShouldPromptDept { get; set; } //Prompt employee to choose department each time 
    } 
} 

또한 조사 결과 ...

string의 모든 속성은 함께 Could not evaluate expression 말 빨간색 느낌표. 이것은 단서입니까 아니면 정상입니까?


또한 조사 결과 ...

이 중요한 여부를하지만 난 코드를 단계별로 그 값을 검사 할 때 나는 그것이 평가 년대 value 동안 actualType == Int32columnType==Int641 것을 알 확실하지.

actualType.Equals(typeof(int))이 있기 때문에 어떤 차이가 있는지 잘 모르겠지만이를 언급했습니다.

+0

MSDN에 따르면, ArgumentException은 두 가지 경우에 발생할 수 있습니다. 대부분의 경우, 귀하의 경우는 두 번째입니다. 'Employee.Id'는 전혀 세터가 있습니까? – Dennis

+0

질문에 제 직원 모델을 추가했지만 예, Setter가 있습니다. –

+0

정확한 예외 메시지 및 인수 이름은 무엇입니까? 내부 예외가 있습니까? – Dennis

답변

1

우리는 GitHub에서 마지막 정보를 찾아 냈습니다. columnType 이후

이 문제를 해결한다 Int64 모델 내의 Id 열의 유형 변경은 Id 열의 Int64이다.

+0

DapperLite가 Alan과 Amy의 제안에 따라 객체를 채우는 방식을 변경했습니다. https://github.com/ryankirkman/DapperLite/commit/43f5588ec15c54c8dea40fec15f3a0b5a9a73f07 –