EntityFramework检索数据自动将表名变复数问题

问题:

EF检索数据自动将表名变复数问题

解决方案:

1、在模型类上添加表名,如:在skusertb类上添加标签:[Table("skusertb")]

代码:

namespace Model
{
    using System;
    using System.Collections.Generic;
    using System.ComponentModel.DataAnnotations;
    using System.ComponentModel.DataAnnotations.Schema;
    [Table("skusertb")]
    public partial class skusertb
    {
        [Key]
        public int yskur_userid { get; set; }
        public string yskur_urname { get; set; }
        public string yskur_urpasswd { get; set; }
        public string yskur_urmingcheng { get; set; }
    }
}

 

2、ef有个默认变复数的属性,把这个属性移除掉就ok了。

对应代码如下(OnModelCreating就是移除变复数的默认标配):

using System.Data.Entity;  
  
namespace SportStore.Models.Repository  
{  
    public class EFDbContext: DbContext  
    {  
        public DbSet<Cartype> table_cartypes { get; set; }  
        public DbSet<City> citylist { get; set; }  
  
        protected override void OnModelCreating(DbModelBuilder modelBuilder) {  
            modelBuilder.Conventions.Remove<System.Data.Entity.ModelConfiguration.Conventions.PluralizingTableNameConvention>();  
        }  
    }  
}  
View Code

 

posted @ 2017-08-01 22:56  stone2012  阅读(225)  评论(0编辑  收藏  举报