Unable to create a constant value of
type
‘Phoenix.Intranet.Web.ClIEntSettings.ComponentRole’.
Only primitive types (‘such as Int32,
String,and GuID’) are supported in
this context.
我明白为什么错误发生.我不明白的是为什么我的代码创建错误.我的比较是反对原始类型.所有比较都是GuID to GuID.该错误明确指出,圭IDs是好的.
该行发生错误(向下):
var vla = (from cir in phoenixEntitIEs.ComponentInRoles
码:
List<ComponentRole> roles;using (imsMembershipEntitIEs entitIEs = new imsMembershipEntitIEs()){ roles = (from role1 in entitIEs.Roles select new ComponentRole{name = role1.Rolename,RoleID = role1.RoleID} ).ToList();}List<Components> componentInRoles;using (PhoenixEntitIEs phoenixEntitIEs = new PhoenixEntitIEs()){ phoenixEntitIEs.Contextoptions.LazyLoadingEnabled = false; componentInRoles = (from component in phoenixEntitIEs.Components select new Components{name = component.name,ComponentID = component.ComponentID,//InRoles = (from componentInRole in phoenixEntitIEs.ComponentInRoles // join role in roles on componentInRole.RoleID equals role.RoleID // where componentInRole.ComponentID == component.ComponentID // select new ComponentRole{RoleID = role.RoleID,name = role.name}) } ).ToList(); foreach (Components cmpent in componentInRoles) { Components cmpent1 = cmpent; //cmpent.InRoles = var vla = (from cir in phoenixEntitIEs.ComponentInRoles join role in roles on cir.RoleID equals role.RoleID where cir.ComponentID == cmpent1.ComponentID select role).ToList(); }}解决方法 EntityFramework和linq to sql都尝试将这样的查询转换为sql IN *** 作符,这些查询是内存中的一部分,另一部分在数据库中.
并且因为你的类哪个角色是一个IEnumerable是不是一个原始类型,它不能被翻译成SQL查询.
您应该首先从数据库中获取内存,然后在内存中加入两个列表.
例如:
var vla = (from cir in phoenixEntitIEs.ComponentInRoles.ToList() join role in roles on cir.RoleID equals role.RoleID where cir.ComponentID == cmpent1.ComponentID select role).ToList();
我希望我能帮忙
总结以上是内存溢出为你收集整理的c# – 在此上下文中仅支持基本类型(如Int32,String和Guid)全部内容,希望文章能够帮你解决c# – 在此上下文中仅支持基本类型(如Int32,String和Guid)所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)