繁体   English   中英

LINQ to Entities不支持'ArrayIndex'

[英]'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();
  1. 您可以获取内存中的所有学生{id,url},然后可以对URL使用split。
  2. 在检查取决于host和...之后,创建一个实体键类型的数组(如果id为int,则为ex:int [])。
  3. 然后可以将数组发送到数据库以获取选定的行

//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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM