entity framework查询生成的语句,为什么没有参数化?

dream__life dream__life 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区

[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();


通过监听生成的SQL语句:

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]


为什么没有使用参数化查询条件呢,应该怎么配置,求教。
...全文
评论
收藏 已收藏
分享
返回顶部
dream__life
.NET社区 62,274 成员 668,968 内容