![](/img/trans.png)
[英]Entity Framework 'ArrayIndex' is not supported in LINQ to Entities
[英]'ArrayIndex' is not supported in LINQ to Entities
LINQ to Entities不支持'ArrayIndex'。
var result = uow.Repository<T_Tenant_Sub_PortalSetting>().Search(x => x.StudentPortalUrl.Split('/')[0].ToString() == filterContext.HttpContext.Request.Url.Host
&& (string.IsNullOrEmpty(x.StudentPortalUrl.Split('/')[1].ToString())) ? true : x.StudentPortalUrl.Split('/')[1].ToString() == WebConfigurationManager.AppSettings["VirtualDirectoryName"])
.IncludeEntity(x => x.T_Tenant_Sub).AsEnumerable().FirstOrDefault();
//imagine this list is my entities IDbSet<...>
List<MyClass> myClasses = new List<MyClass>();
//you can read all entities {id,url} in RAM
Dictionary<int, string> keyValues =
new Dictionary<int, string>();
myClasses
.Where(x => true/*some conditions here*/)
.Select(x => new { x.Id, x.Url })
.ToList()//here data fetched from db
.ForEach(x => keyValues.Add(x.Id, x.Url));
//now you can use split
int[] SelectedIds = keyValues
.Where(x => x.Value.Split('/')[0] == "host"
/*&& another conditions here*/)
.Select(x=>x.Key)
.ToArray();
//now you can pass an array to db for fetching data
//as dbset
myClasses
.Where(x =>
SelectedIds.Contains(x.Id));
int[] SelectedIds = keyValues.Where(x => x.Value.Split('/')[0] == "host"/*&& another conditions here*/)
.Select(x=>x.Key)
.ToArray();
//now you can pass an array to db for fetching data
//as dbset
myClasses.Where(x => SelectedIds.Contains(x.Id));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.