zoukankan      html  css  js  c++  java
  • model attribute

    model attribute,字面意思,给model加attribute以配置数据库

    主键

    public class OrderDetail
    {
        [Key]
        public int OrderDetailID { get; set; }
        public int OrderID { get; set; }
        public int ProductID { get; set; }
        public int Quantity { get; set; }
        public Order Order { get; set; }
    }

    并发令牌

    public class Customer
    {
        public int CustomerId { get; set; }
        public string LastName { get; set; }
        public string FirstName { get; set; }
        public string Address { get; set; }
    
        [ConcurrencyCheck]
        public string Version { get; set; }
    }

    不映射

    [NotMapped]
    public class BlogMetadata
    {
        public DateTime LoadedFromDatabase { get; set; }
    }
    或 
    public class Blog
    {
        public int BlogId { get; set; }
        public string Url { get; set; }
    
        [NotMapped]
        public DateTime LoadedFromDatabase { get; set; }
    }

    必要

    public class Blog
    {
        public int BlogId { get; set; }
        [Required]
        public string Url { get; set; }
    }

    最大长度

    public class Person
    {
        public int PersonId { get; set; }
    
        [MaxLength(50)]
        public string LastName { get; set; }
    
        [MaxLength(50)]
        public string FirstName { get; set; }
    }

    最短长度

    public class Person
    {
        public int PersonId { get; set; }
    
        [MinLength(3)]
        public string LastName { get; set; }
    
        [MinLength(3)]
        public string FirstName { get; set; }
    }

    字符串长度

    public class Person
    {
        public int PersonId { get; set; }
    
        [StringLength(50)]
        public string LastName { get; set; }
    
        [StringLength(50)]
        public string FirstName { get; set; }
    }

    外键

    public class OrderDetail
    {
        public int OrderDetailID { get; set; }
        public int OrderID { get; set; }
        public int ProductID { get; set; }
        public int Quantity { get; set; }
    
        [ForeignKey("OrderID")]
        public Order Order { get; set; }
    }
    
    public class Order
    {
        public int OrderID { get; set; }
        public int CustomerID { get; set; }
        public int EmployeeID { get; set; }
        public DateTime OrderDate { get; set; }
        public List<OrderDetail> OrderDetails { get; set; }
    }

    时间戳

    public class Person
    {
        public int PersonId { get; set; }
        public string LastName { get; set; }
        public string FirstName { get; set; }
    
        [Timestamp]
        public byte[] TStamp { get; set; }
    }

    表映射

    [Table("UserInfo")]
    public class Person
    {
        public int PersonId { get; set; }
        public string LastName { get; set; }
        public string FirstName { get; set; }
    }

    列名映射

    public class Person
    {
        public int PersonId { get; set; }
    
        [Column("LName")]
        public string LastName { get; set; }
    
        [Column("FName")]
        public string FirstName { get; set; }
    }
  • 相关阅读:
    智能车回忆
    自动化面试问题
    先进控制理论(转载)
    电力电子技术(转载)
    微型计算机原理及应用复习(转载)
    c语言中数值交换用值传递和地址传递
    unity调用苹果端方法
    unity调用安卓arr方法
    unity mono单例
    loading通用界面笔记
  • 原文地址:https://www.cnblogs.com/nocanstillbb/p/11562556.html
Copyright © 2011-2022 走看看