Posts

Showing posts with the label linq

LINQ contains exactly matching

LINQ contains exactly matching We have the following class structure and want to query all user who has at least all roles or more from the mustHaveRole Queryparameter. If someone has a good idea that would be cool :-) public class User { public Guid UserId { get; set; } public string Username { get; set; } public ICollection<UserRole> Roles { get; set; } = new HashSet<UserRole>(); } public class UserRole { public virtual User User { get; set; } public Guid UserId { get; set; } public virtual Role Role { get; set; } public Guid RoleId { get; set; } } public class Role { public Guid RoleId { get; set; } public string RoleName { get; set; } public ICollection<User> Users { get; set; } = new HashSet<User>(); } public class QueryHandler { readonly List<User> Users = new List<User>(); public IEnumerable<User> Handle(List<Guid> musthaveRoles) { var queryResult = from u in U...

Convert string to long type and use in a linq query within asp.net MVC

Convert string to long type and use in a linq query within asp.net MVC Is it possible within Linq in C#, to convert a string field in a database, to a long type - and use it in the query? Here, tme is a unix time (long) - but the field in the database, targetdate - is a string. I've tried: var qbt = db.Calls .Where(x => x.team == id && long.Parse(x.targetdate) <= tme); However I get the message: LINQ to Entities does not recognize the method 'Int64 Parse(System.String)' method, and this method cannot be translated into a store expression. LINQ to Entities does not recognize the method 'Int64 Parse(System.String)' method, and this method cannot be translated into a store expression. I know you can convert before the linq query, but is there any way of using it WITHIN the linq query? Thanks for any help, Mark "but the field in the database, targetdate - is a string" - there's your first problem.... ...