我正在尝试使用ServiceStack OrmLite,但是现在我对此异常感到困惑:A first chance exception of type 'System.NullReferenceException' occurred in Unknown Module.
也没有堆栈跟踪。
这是我的OrmLite代码:
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args) {
string DbConnection = "SERVER=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=xxx.xxx.xxx.xxx)(PORT=9530))(CONNECT_DATA=(SERVICE_NAME=MYSID)));uid=myusername;pwd=mypassword";
var dbFactory = new OrmLiteConnectionFactory(DbConnection, false, OracleDialect.Provider);
using (var db = dbFactory.Open()) {
var res = db.Select<Einduk>().Take(10);
foreach (var einduk in res) {
Console.WriteLine(einduk.ToString());
}
}
Console.ReadLine();
}
}
}
这是我的模特课:
namespace ConsoleApplication1
{
public class Einduk
{
[PrimaryKey]
public string Akaun { get; set; }
public string Jenis { get; set; }
public string Bakaun { get; set; }
public string Oldac { get; set; }
public string Plgid { get; set; }
public string Pnama { get; set; }
public string Almat { get; set; }
public string Kslah { get; set; }
public DateTime Trikh { get; set; }
public decimal Amaun { get; set; }
public override string ToString() {
return string.Format("Jenis: {0}, Akaun: {1}, Bakaun: {2}, Oldac: {3}, Plgid: {4}, Pnama: {5}, Almat: {6}, Kslah: {7}, Trikh: {8}, Amaun: {9}", Jenis, Akaun, Bakaun, Oldac, Plgid, Pnama, Almat, Kslah, Trikh, Amaun);
}
}
}
这是我的表格,请注意表格没有主键。但在我的模型中,我将Akaun
设置为主键,因为我知道它是唯一的。 这会导致问题吗?
CREATE TABLE "EINDUK"
(
"JENIS" CHAR(1 BYTE),
"AKAUN" VARCHAR2(40 BYTE),
"BAKAUN" VARCHAR2(50 BYTE),
"OLDAC" VARCHAR2(20 BYTE),
"PLGID" VARCHAR2(15 BYTE),
"PNAMA" VARCHAR2(100 BYTE),
"ALMAT" VARCHAR2(282 BYTE),
"KSLAH" VARCHAR2(508 BYTE),
"TRIKH" DATE,
"AMAUN" NUMBER
)
答案 0 :(得分:3)
这是因为在我的模型类中,我没有将我的属性设置为可空,就像这样..
public DateTime? Trikh { get; set; }
public decimal? Amaun { get; set; }