首页 新闻 会员 周边 捐助

模型关系怎样建立,我设定的好似有错,请指教

0
[待解决问题]

 有表cu_product_grphd(key:grph_parent、grph_code)和cu_product_grpdtl(grpd_code、grpd_son),数据记录如图:

我建立的模型如下view Code:

 1     public class grphdmas
 2     {
 3         [Key, Column("mdlCode", Order = 1)]
 4         [StringLength(20), Display(Name = "Model")]
 5         public string mdlCode { get; set; }
 6         [StringLength(1), Display(Name = "是否分組")]
 7         public string grph_flg { get; set; }
 8 
 9         public virtual IList<cu_product_grphd> cu_product_grphd { get; set; }
10     }
11 
12     public class cu_product_grphd
13     {
14         [Key, Column("grph_parent", Order = 1), ForeignKey("grphdmas")]
15         [StringLength(20), Display(Name = "Model")]
16         public string grph_parent { get; set; }
17         [Key, Column("grph_code", Order = 2)]
18         [StringLength(20), Display(Name = "備案Model組")]
19         public string grph_code { get; set; }
20         [StringLength(1), Display(Name = "是否分組")]
21         public string grph_flg { get; set; }
22         [StringLength(50), Display(Name = "備註")]
23         public string grph_rmk { get; set; }
24         [StringLength(8), Display(Name = "創建人")]
25         public string grph_createUsr { get; set; }
26         [Display(Name = "創建時間")]
27         public System.DateTime grph_createDte { get; set; }
28         public string lusr { get; set; }
29         public System.DateTime ldte { get; set; }
30 
31         public virtual grphdmas grphdmas { get; set; }
32         public virtual IList<cu_product_grpdtl> cu_product_grpdtls { get; set; }
33     }
34 
35     public class cu_product_grpdtl
36     {
37         [Key, Column("grpd_code", Order = 1), ForeignKey("cu_product_grphd")]
38         [StringLength(20), Display(Name = "備案Model組")]
39         public string grpd_code { get; set; }
40         [Key, Column("grpd_son", Order = 2)]
41         [StringLength(20), Display(Name = "子層")]
42         public string grpd_son { get; set; }
43         [StringLength(1), Display(Name = "類別")]
44         public string grpd_type { get; set; }
45         [Display(Name = "用量")]
46         public decimal grpd_usg { get; set; }
47         [StringLength(50), Display(Name = "備註")]
48         public string grpd_rmk { get; set; }
49 
50         public cu_product_grphd cu_product_grphd { get; set; }
51     }
View Code

是不这样建的关系有问题,总是报错,请大家指点。

MVC
sunny813的主页 sunny813 | 菜鸟二级 | 园豆:202
提问于:2014-04-26 13:56
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册