c# [key]

来源:互联网 发布:玩客云抢购软件 编辑:程序博客网 时间:2024/05/16 08:08
  1. publicclass CartItem   
  2.  { [Key]     
  3.    public stringItemId {get; set; }         
  4. publicstring CartId{ get;set; }        
  5.  public intQuantity {get; set; }        
  6.  public System.DateTimeDateCreated {get; set; }        
  7.  public intProductId {get; set; }       
  8.   public virtualProduct Product{ get;set; }      }
  9. the code overrides the default behavior by using the data annotation [Key] attribute. TheKey attribute of the ItemId property specifies that the ItemID property is the primary key.
  10. 解释:key 属性 标注 itemid为主属性