4.1下多对多Models层出错

Topics: Developer Forum
Mar 11, 2012 at 5:07 PM

代码:

    public class User : DbObjectModel<User>
    {
        [Length(32)]
        public string 密码 { get; set; }
        [Length(20)]
        public string 用户名 { get; set; }
        [Length(20)]
        public string 手机号码 { get; set; }

        [HasAndBelongsToMany(OrderBy = "Id")]
        public IList<Dating> Datings { get; set; }

        public static User New(string _密码, string _用户名, string _手机号码) { return new User { 密码 = _密码, 用户名 = _用户名, 手机号码 = _手机号码 }; }
    }

    public class Dating : DbObjectModel<Dating>
    {
        [Length(20)]
        public string 主题 { get; set; }
        [Length(50), AllowNull]
        public string 备注 { get; set; }

        public DateTime 发布时间 { get; set; }
        public DateTime 开始时间 { get; set; }

        [HasAndBelongsToMany(OrderBy = "Id")]
        public IList<User> Users { get; set; }

        public static Dating New(string _主题, string _备注, DateTime _发布时间, DateTime _开始时间) { return new Dating { 备注=_备注, 发布时间=_发布时间, 开始时间=_开始时间, 主题=_主题}; }
    }

错误:

错误    11    Process Model : AccessModels.Dating
Lephone.Data.DataException: Property [Users] should have private setter but not

Coordinator
Mar 12, 2012 at 4:00 AM

Property [Users] should have private setter but not 这句话你看不懂?

Apr 25, 2012 at 8:46 AM

Dear Lifeng

I am using your DbEntry framework and I am very happy with it! Wounderful solution!

With version 4.1 have a problem with "HasMany" The compilation error "Property [Users] should have private setter but not" I cant undersatand what does it mean.

my  models:

    [DbTable("Table1")]
    public class SchwangerschaftskontrolleRead : DbObjectModel<SchwangerschaftskontrolleRead>
    {
        public long PregnancyId { getset; }
        public DateTime Datum { getset; }
        public int Woche { getset; }
        public int Tag { getset; }
        public int Art { getset; }
        public long? ArztId { getset; }
        public long? PflegeId { getset; }
        [Length(20), AllowNull]
        public string ArztKurzel { getset; }
        [Length(20), AllowNull]
        public string PflegeKurzel { getset; }
        [AllowNull]
        public string Bemerkungen { getset; }
 
        [HasMany(OrderBy = "Id")]
        public IList<KontrolleUnit> Units { getset; }
 
    }
 
    [DbTable("Table2")]
    public class KontrolleUnit : DbObjectModel<KontrolleUnit>
    {
        public string Code { getset; }
        public string Resultat { getset; }
        [BelongsToDbColumn("SskId")]
        public SchwangerschaftskontrolleRead Owner { getset; }
    }

Could you please help me to solve this problem

Coordinator
Apr 25, 2012 at 10:00 AM
        [HasMany(OrderBy = "Id")]
        public IList<KontrolleUnit> Units { get; private set; }
Apr 27, 2012 at 3:56 PM

老大,为啥要加个private啊~~~

老大我还欠你1000大洋呢,我可没忘,我打算先一直欠着了!然后攒着利息一起双倍还你!

老大,我最近进军移动领域了。话说你不开个新浪微博么。

另外,老大,虽然EF还比不上DbEntry,但是总体已经很牛逼了……

再次感谢DbEntry……

Coordinator
Apr 28, 2012 at 3:27 AM

因为赋值也没用,反而使不太了解的人误以为有效,加了 private 的话,编译器就会阻止这种操作。

至于EF,相信它也会越来越好的,不过我觉得作为微软,总是有一些东西舍不得放下,有些地方为了大而全,都做了,但是又不太够用,总有些鸡肋感。

新浪微博有,不过从不发言,G+上还是会说说话的......