原文网址:https://www.cnblogs.com/wangdash/p/12342471.html
/// EF查看SQL2种方式 /// 1. 通过数据库的sqlprofiler /// 2. context.Database.Log += s => Console.WriteLine($"当前执行sql:{s}"); using (CodeFirst context = new CodeFirst()) { context.Database.Log += s => Console.WriteLine($"当前执行sql:{s}"); Llogin l_Login = context.L_login.Find(1); Llogin l_login1 = context.L_login.Where(l => l.id1 == 3).FirstOrDefault(); }
//1. 特性映射 [Table("L_login")] public partial class Llogin { [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")] [StringLength(50)] public string name1 { get; set; } } //2.OnModelCreating完成链式映射 protected override void OnModelCreating(DbModelBuilder modelBuilder) { modelBuilder.Entity<Llogin>().ToTable("L_login").Property(n => n.name1).HasColumnName("name"); } //3. 映射类文件 public class LloginMapping : EntityTypeConfiguration<Llogin> { public LloginMapping() { this.ToTable("L_login"); this.Property(c => c.name1).HasColumnName("name"); } } protected override void OnModelCreating(DbModelBuilder modelBuilder) { modelBuilder.Configurations.Add(new LloginMapping()); }
标签:Llogin,映射,SQL2,EF,modelBuilder,context,login,public From: https://www.cnblogs.com/bruce1992/p/16884959.html