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

學(xué)無(wú)先后,達(dá)者為師

網(wǎng)站首頁(yè) 編程語(yǔ)言 正文

EF使用Code?First模式給實(shí)體類添加復(fù)合主鍵_實(shí)用技巧

作者:.NET開發(fā)菜鳥 ? 更新時(shí)間: 2022-05-03 編程語(yǔ)言
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; }

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

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

使用特性Key和Column設(shè)置復(fù)合主鍵,Key表示字段是主鍵,Order用來(lái)設(shè)置主鍵的順序。使用Key和Column需要添加命名空間:

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

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

欄目分類
最近更新