我希望能够使用Entity Framework从数据库中获取一些值。
我对以下问题存在疑惑:
在Entity Framework查询中,
new ClassName
和new ClassName()
之间的区别
代码1
dbContext.StatusTypes.Select(s => new StatusTypeModel() { StatusTypeId =
s.StatusTypeId, StatusTypeName = s.StatusTypeName }).ToList();
代码 2
dbContext.StatusTypes.Select(s => new StatusTypeModel { StatusTypeId =
s.StatusTypeId, StatusTypeName = s.StatusTypeName }).ToList();
当我创建一个new StatusTypeModel
和new StatusTypeModel()
对象时,您可以看到变化。
- 这两个查询都适用于我。但是我不知道代码1和代码2之间的区别。