日本免费高清视频-国产福利视频导航-黄色在线播放国产-天天操天天操天天操天天操|www.shdianci.com

學無先后,達者為師

網站首頁 編程語言 正文

EF使用Code?First模式給實體類添加復合主鍵_實用技巧

作者:.NET開發菜鳥 ? 更新時間: 2022-05-03 編程語言
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Web;

namespace MyFirstMvcApp.Models
{
    /// 
    /// 登錄記錄
    /// 
    public class LoginRecordInfo
    {
        /// 
        /// 登錄的郵件地址(主鍵)
        /// 
        [Key,Column(Order=1)]
        public string Email { get; set; }

        /// 
        /// 登錄的客戶端IP
        /// 
        public string LoginHostIP { get; set; }

        /// 
        /// 登錄的客戶端主機名
        /// 
        public string LoginHostName { get; set; }

        /// 
        /// 登錄時間(主鍵)
        /// 
        [Key,Column(Order=2)]
        public DateTime LoginTime { get; set; }
    }
}

使用特性Key和Column設置復合主鍵,Key表示字段是主鍵,Order用來設置主鍵的順序。使用Key和Column需要添加命名空間:

  • Key的命名空間:System.ComponentModel.DataAnnotations;
  • Column的命名空間:System.ComponentModel.DataAnnotations.Schema;

原文鏈接:https://www.cnblogs.com/dotnet261010/p/7275510.html

欄目分類
最近更新