linq

SQL Linq Many To Many

心已入冬 提交于 2021-01-29 03:02:56
问题 I have a database with a User's and Role's table. Each user can be in lots of roles, so there is a 'middle' table called UserRoles that simply contains a RoleId and UserId. Now I need to get all the roles attached to a User. public IEnumerable<Role> GetAllRoles(int UserId) { var query = from R in _db.Roles where RolesTbl.UserRoles.UserId == UserId select R; return query; } Now the query above doesnt work, "RolesTbl.UserRoles.UserId" I cant referance it in this way because of the Many to Many.

Method not found: 'System.Object Newtonsoft.Json.Linq.JToken.ToObject(System.Type)'

送分小仙女□ 提交于 2021-01-28 21:49:59
问题 Our mvc project with json.net running without any problem on every developer except the one with the new windows 8.1 system. How can we find source of the method not found problem ? details of the exception ; [MissingMethodException: Method not found: 'System.Object Newtonsoft.Json.Linq.JToken.ToObject(System.Type)'.] ExtensionMethods.Eval(Object o, String propertyName) in c:\Users\maxSEPHIROTH\Documents\Visual Studio 2012\Projects\LogiSysMvc\LogiSysMvc\ClassLibrary\ExtensionMethods.cs:136

EfCore 3.1.3 throwing Execption for OrderBy

六眼飞鱼酱① 提交于 2021-01-28 21:07:28
问题 I am trying to Order by a query using the following efcore query Getting the PropertyInfo for the column which needs to be orderedBy using this below var propertyInfo = typeof(TableVM).GetProperty("Type"); The EfCore Query db.Table **//LinkKit Extension Method** .AsExpandable() .Where(whereClause) .Select(m => new TableVM { id= m.Id, name = m.Name, description = m.Description, type = m.Type, status = m.Status }) **// Conversion of the OrderBy fails, which throws an exception saying it can't

EfCore 3.1.3 throwing Execption for OrderBy

假装没事ソ 提交于 2021-01-28 20:35:50
问题 I am trying to Order by a query using the following efcore query Getting the PropertyInfo for the column which needs to be orderedBy using this below var propertyInfo = typeof(TableVM).GetProperty("Type"); The EfCore Query db.Table **//LinkKit Extension Method** .AsExpandable() .Where(whereClause) .Select(m => new TableVM { id= m.Id, name = m.Name, description = m.Description, type = m.Type, status = m.Status }) **// Conversion of the OrderBy fails, which throws an exception saying it can't

Multiple Values Contains with Dynamic Linq

萝らか妹 提交于 2021-01-28 19:44:49
问题 How to use Multiple value with Contain in Dynamic Linq. Expected With Normal Linq : using System; using System.Linq; public class Simple { public static void Main() { string[] names = { "Burke", "Laptop", "Computer", "Mobile", "Ahemed", "Sania", "Kungada", "David","United","Sinshia" }; string[] vars = {"i","a"}; var query = names.Where(i=> vars.Any(j=>i.Contains(j))).ToList(); Console.WriteLine(query.Count); } } Expected SQL SELECT * FROM User WHERE (NAME LIKE '%a%'OR NAME LIKE '%b%') Tried

LINQ & IEnumerable<String> Re-evaluation

强颜欢笑 提交于 2021-01-28 19:30:37
问题 Good morning, I wrote the following LINQ query public static Func<String, IEnumerable<String>> ListaCorreccoes = (StrPalavra) => { return (from StrTmp in ListaPossiveisCorreccoes(StrPalavra) from StrTmp2 in ListaPossiveisCorreccoes(StrTmp) where PalavraConhecida(StrTmp2) select StrTmp2).Distinct(); }; which, to my surprise, is much faster than using two foreach cicles. After running this function using ListaTmp = ListaCorreccoes("comutador"); , where ListaTmp is of type IEnumerable<String> ,

LINQ & IEnumerable<String> Re-evaluation

淺唱寂寞╮ 提交于 2021-01-28 19:27:25
问题 Good morning, I wrote the following LINQ query public static Func<String, IEnumerable<String>> ListaCorreccoes = (StrPalavra) => { return (from StrTmp in ListaPossiveisCorreccoes(StrPalavra) from StrTmp2 in ListaPossiveisCorreccoes(StrTmp) where PalavraConhecida(StrTmp2) select StrTmp2).Distinct(); }; which, to my surprise, is much faster than using two foreach cicles. After running this function using ListaTmp = ListaCorreccoes("comutador"); , where ListaTmp is of type IEnumerable<String> ,

Entity framework Select first item in group that satisfies condition or just first item

眉间皱痕 提交于 2021-01-28 14:38:07
问题 I have a table with localized values like this LocalizedFruits ID | LOCALE | NAME 1 | en_UK | Banana 2 | da_DK | Banan 3 | de_DE | Banane 4 | zh-CHS | 香蕉 Then i want to autocomplete the value the user is typing, if the user is chinese it's all good but if it's people from one of the other cultures a problem arises, when they type "ba" the user will get 3 results that are the same thing. therefore i group the result by Locale. What i want to do is i want to get the group with the same locale

Entity framework Select first item in group that satisfies condition or just first item

怎甘沉沦 提交于 2021-01-28 14:34:13
问题 I have a table with localized values like this LocalizedFruits ID | LOCALE | NAME 1 | en_UK | Banana 2 | da_DK | Banan 3 | de_DE | Banane 4 | zh-CHS | 香蕉 Then i want to autocomplete the value the user is typing, if the user is chinese it's all good but if it's people from one of the other cultures a problem arises, when they type "ba" the user will get 3 results that are the same thing. therefore i group the result by Locale. What i want to do is i want to get the group with the same locale

Concat causes stack overflow if called multiple times

断了今生、忘了曾经 提交于 2021-01-28 12:12:46
问题 Application accidentally crashed with stack overflow error. After research I found that the reason of crash is following code: foreach (var item in items) { result = result.Concat(item.Data); } This is concatenation of multiple IEnumerable s. Application crashed when items contained 10,000 elements. SelectMany fixed this issue. But still... Why Concat extension causes stack overflow here? 回答1: Remember that the result of Concat is not a collection - it's a query . So your "result" is