2

我正在尝试 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
)
4

1 回答 1

3

这是因为在我的模型类中,我没有将我的属性设置为可为空,就像这样..

public DateTime? Trikh { get; set; }
public decimal? Amaun { get; set; }
于 2013-07-17T10:52:48.253 回答