标签:检索 types pos rmi conf isp div epo color
问题:
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>(); } } }
标签:检索 types pos rmi conf isp div epo color
原文地址:http://www.cnblogs.com/stone2012/p/7271481.html