62,244
社区成员




[Table("Sys_User", Schema = "dbo")]
public class User
{
[Key]
public int ID { get; set; }
[Display(Name = "账号")]
[StringLength(20)]
[Required]
public string Account { get; set; }
[Display(Name = "姓名")]
[StringLength(20)]
[Required]
public string Name { get; set; }
[Display(Name = "所属部门")]
public int? DeptID { get; set; }
[Display(Name = "性别")]
[StringLength(10)]
[Required]
public string Sex { get; set; }
[Display(Name = "密码")]
[StringLength(50)]
[Required]
public string Password { get; set; }
[Display(Name = "邮箱")]
[StringLength(50)]
public string Email { get; set; }
[Display(Name = "是否启用")]
[Required]
public bool Enabled { get; set; }
[Display(Name = "工作电话")]
[StringLength(50)]
public string OfficePhone { get; set; }
[Display(Name = "手机号")]
[StringLength(50)]
public string CellPhone { get; set; }
[Display(Name = "备注")]
[StringLength(100)]
public string Remark { get; set; }
[Display(Name = "上次登录时间")]
public DateTime? LastLoginTime { get; set; }
[Display(Name = "创建时间")]
public DateTime? CreateTime { get; set; }
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.Entity;
using System.Data.Entity.ModelConfiguration.Conventions;
namespace WebApplication1.Models
{
public class EFContext : DbContext
{
public EFContext() : base("Default")
{
}
public DbSet<User> Users { get; set; }
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
// 禁用默认表名复数形式
modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
base.OnModelCreating(modelBuilder);
}
}
}
EFContext db = new EFContext();
Models.User u = db.Users.Where(p => p.Account == "admin").FirstOrDefault();
SELECT TOP (1)
[Extent1].[ID] AS [ID],
[Extent1].[Account] AS [Account],
[Extent1].[Name] AS [Name],
[Extent1].[DeptID] AS [DeptID],
[Extent1].[Sex] AS [Sex],
[Extent1].[Password] AS [Password],
[Extent1].[Email] AS [Email],
[Extent1].[Enabled] AS [Enabled],
[Extent1].[OfficePhone] AS [OfficePhone],
[Extent1].[CellPhone] AS [CellPhone],
[Extent1].[Remark] AS [Remark],
[Extent1].[LastLoginTime] AS [LastLoginTime],
[Extent1].[CreateTime] AS [CreateTime]
FROM [dbo].[Sys_User] AS [Extent1]
WHERE N'admin' = [Extent1].[Account]