我是ServiceStack中的ORMLite新手。我試圖查詢現有的MySQL數據庫。我創建這個POCO在MySQL中對應於我的表佈局:ServiceStack ORMLite未填充來自MySQL的結果
[Alias("checks")]
public class Check
{
[AutoIncrement]
[PrimaryKey]
public long check_id { get; set; }
public long room_state_id { get; set; }
public DateTime? entry_stamp { get; set; }
public int student_id { get; set; }
public string reason { get; set; }
public string comments { get; set; }
public long check_type_id { get; set; }
public DateTime? check_dt { get; set; }
public byte grace { get; set; }
public DateTime curfew_dt { get; set; }
public int excused_by { get; set; }
public string status { get; set; }
public int points { get; set; }
public string check_class { get; set; }
public int leave_id { get; set; }
public DateTime night_of { get; set; }
public DateTime violation_dt { get; set; }
public string excused_reason { get; set; }
public DateTime? excused_dt { get; set; }
public sbyte imported { get; set; }
}
這裏的MySQL表定義
CREATE TABLE checks (
check_id bigint(11) NOT NULL AUTO_INCREMENT,
room_state_id bigint(11) NOT NULL DEFAULT 0,
entry_stamp datetime DEFAULT NULL,
student_id int(11) NOT NULL DEFAULT 0,
reason varchar(60) DEFAULT NULL,
comments text DEFAULT NULL,
check_type_id bigint(20) NOT NULL DEFAULT 0,
check_dt datetime DEFAULT NULL,
grace tinyint(4) UNSIGNED NOT NULL DEFAULT 0,
curfew_dt datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
excused_by int(11) NOT NULL DEFAULT 0,
status char(1) NOT NULL DEFAULT '',
points int(11) NOT NULL DEFAULT 0,
check_class char(2) NOT NULL DEFAULT '',
leave_id int(11) NOT NULL DEFAULT 0,
night_of date NOT NULL DEFAULT '0000-00-00',
violation_dt datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
excused_reason varchar(255) NOT NULL DEFAULT '',
excused_dt datetime DEFAULT '0000-00-00 00:00:00',
imported tinyint(1) NOT NULL DEFAULT 0,
PRIMARY KEY (check_id),
INDEX check_class (check_class),
INDEX check_dt (check_dt),
INDEX check_type_id (check_type_id),
INDEX excused_by (excused_by),
INDEX leave_id (leave_id),
INDEX night_of (night_of),
INDEX status (status),
INDEX student_id (student_id)
)
和我想要一些成果使用來獲得:
public object Get(GetChecks request)
{
return new GetChecksResponse { Results = Db.Select<Check>(q => q.student_id == request.StudentId) };
}
當我測試這個,我得到了一個結果表的正確的行數,但沒有填充數據(所有行中的所有字段爲空或0,除了日期時間有一個無意義的日期)。我怎樣才能找到爲什麼ORMLite沒有填充我的POCO?
UPDATE:
測井顯示了很多的DateTime轉換錯誤:
2016-01-23 15:35:53.5869|ERROR|OrmLiteWriteCommandExtensions|MySql.Data.Types.MySqlConversionException: Unable to convert MySQL date/time value to System.DateTime
在MySql.Data.Types.MySqlDateTime.GetDateTime() 在MySql.Data.MySqlClient.MySqlDataReader.GetValue( INT32ⅰ) 在MySql.Data.MySqlClient.MySqlDataReader.GetValues(對象[]值) 在ServiceStack.OrmLite.OrmLiteWriteCommandExtensions.PopulateWithSqlReader [T](T objWithProperties,IOrmLiteDialectProvider dialectProvider,IDataReader的閱讀器,Tuple`3 []索引緩存,對象[]值)
確實[登錄](https://github.co m/ServiceStack/ServiceStack/wiki/Logging)顯示任何錯誤?您是否使用OrmLite創建表,即:db.CreateTable()'或者您是否試圖將其映射到現有表?如果是這樣,請提供使用的創建表定義。 –
mythz