在实际项目中,可能会使用到奇葩的数据表,没有主键,也没有not null 列。
我们知道EF Code First 模式下,如果没有主键和not null 列,是没办法自动生成映射实体类的。此种情况下要手动生成,并且需要创建伪主键。
1. 手动生成实体类
namespace entityTest2
{
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.Spatial;
public partial class FXRATES
{
public DateTime? FXDate { get; set; }
[StringLength(3)]
public string CountryCode { get; set; }
[StringLength(3)]
public string USDCode { get; set; }
public Double FXrateUSD { get; set; }
public Double FXRateLocal { get; set; }
[StringLength(50)]
public string CurrencyName { get; set;