我在实体框架中有一个简单的类,如下所示:
public class Merchandising
{
public int Id { get; set; }
public int Index { get; set; }
public int CategoryId { get; set; }
public int? CardId { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
在数据库中,这有大约1000行,直接查询只需不到一秒钟,但是当我执行此语句时,运行最多需要55秒 - 我觉得这很奇怪.任何人都可以对此有所了解吗?
var mm = a.Merchandisings.ToList();
var m = mm.Where(f => f.CategoryId == catId).ToList();
Run Code Online (Sandbox Code Playgroud)
catId是一个整数值,mm需要几分之一秒才能执行.mm返回大约1000行,m返回40行.M需要大约55秒才能执行.
我假设虽然CategoryId并且CardId它们都链接到其他类(并且是大数据对象),但是没有加载数据,因为没有延迟加载.
我真的不明白为什么执行m需要这么长时间,我想这与公平框架缺乏知识有关.有人可以帮忙吗?
我有这个LINQ从通用列表中获取特定类成员的不同值:
var distinctDescriptions = itemsForMonthYearList.Select(x => x.ItemDescription).Distinct();
Run Code Online (Sandbox Code Playgroud)
通用列表以这种方式定义:
List<ItemsForMonthYear> itemsForMonthYearList;
Run Code Online (Sandbox Code Playgroud)
这堂课是:
public class ItemsForMonthYear
{
public String ItemDescription { get; set; }
public String monthYr { get; set; }
public int TotalPackages { get; set; }
public Decimal TotalPurchases { get; set; }
public Decimal AveragePrice { get; set; }
public Double PercentOfTotal { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
我认为这会奏效:
var distinctDescriptions = itemsForMonthYearList.Select(x => x.ItemDescription).Distinct().OrderBy(x => x.ItemDescription);
Run Code Online (Sandbox Code Playgroud)
...但它甚至没有编译:
" 'string'不包含'ItemDescription'的定义,也没有扩展方法'ItemDescription'接受'string'类型的第一个参数(你是否缺少using指令或汇编引用?) "
如何按字母顺序对不同的值进行排序?
在global.asax中定义并填充了Dictionary
public static Dictionary<Guid, string> GlobalUserDictionary;
Run Code Online (Sandbox Code Playgroud)
在控制器中,某些逻辑通过EF DbContext从db加载数据
var db = new DbModel();
var visits = db.Visits.Select(d => new
{
Id = d.Id,
UserId = d.UserId,
User = MvcApplication.GlobalUserDictionary[d.UserId]
});
Run Code Online (Sandbox Code Playgroud)
但控制器抛出异常:
System.NotSupportedException:LINQ to Entities无法识别方法'System.String get_Item(System.Guid)'方法,并且此方法无法转换为存储表达式.
如何将dbcontext模型与Dictionary等外部数据资源或类似的东西相结合?
目前我正在尝试将我的自定义对象连接到由Visual Studio自动生成的Application User.
Employee.cs
public class Employee
{
[Display(Name = "ID")]
[Key]
public int EmployeeID { get; set; }
[ForeignKey("ApplicationUser")]
public int ApplicationUserID { get; set; }
[Required]
[DataType(DataType.Currency)]
public decimal MonthlySalary { get; set; }
[Required]
public string Experience { get; set; }
[Required]
public string Description { get; set; }
public string PhotoURL { get; set; }
public virtual ApplicationUser ApplicationUser { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
错误是:
运行所选代码生成器时出错:'无法检索Models.Tables.Employee的元数据.在模型生成期间检测到一个或多个验证错误:Parent_ApplicationUser_Target_Parent_ApplicationUser_Source ::参照约束的从属角色中的所有属性的类型必须与主体角色中的相应属性类型相同.实体"Parent"上的属性"ApplicationUserlD"的类型与引用约束"Parent_ApplicationUser"中实体"ApplicationUser"上的属性"Id"的类型不匹配.Employee ApplicationUser目标Employee ApplicationUser Source ::引用约束的从属角色中的所有属性的类型必须与主体角色中的相应属性类型相同.实体'Employee上的属性'ApplicationUserlD'的类型与引用约束'Employee_ApplicationUser中的实体'ApplicationUser'上的属性'Id'的类型不匹配.
Parent表包含相同的ApplicationUser引用Employee …
当我将所有内容放在一个语句中时,我有一个完美的查询:
var rs = db.SerialNumbers
.Join(db.ProductLines, sn => sn.ProductLineId, pl => pl.Id, (sn, pl) => new { pl.Id, pl.Category, sn.UserId })
.Where(sn => sn.UserId == userId)
.Select(sn => new { sn.Id, sn.Category })
.Distinct();
Run Code Online (Sandbox Code Playgroud)
但是我需要为UserId添加条件.我只想过滤userId中是否有条目,即userId> 0.所以我改为查询:
var rs = db.SerialNumbers
.Join(db.ProductLines, sn => sn.ProductLineId, pl => pl.Id, (sn, pl) => new { pl.Id, pl.Category, sn.UserId });
if(userId > 0)
{
rs = rs.Where(sn => sn.UserId == userId);
}
rs = rs.Select(sn => new { sn.Id, sn.Category });
Run Code Online (Sandbox Code Playgroud)
我在编译时遇到这个错误:
无法将类型隐式转换
System.Linq.IQueryable<AnonymousType#1> …
我正在尝试将 portainer 部署到我的本地 docker。我在 Windows 10 上运行 Docker CE 18.0.6.0 版本。我尝试按照这两个页面中的步骤操作:
但我一直试图运行以下命令:
docker run -d -p 9000:9000 --name portainer --restart always -v portainer_data:/data portainer/portainer -H tcp://10.0.75.1:2375
Run Code Online (Sandbox Code Playgroud)
Docker 总是以相同的消息响应:
来自守护进程的错误响应:无效的卷规范:'portainer_data:/data'
我使用以下命令创建了卷:
docker volume create portainer_data
Run Code Online (Sandbox Code Playgroud)
知道可能是什么吗?