[Solved] How to write a Linq to entity statement, using sql not in operator [duplicate]

You can write something like that: var query = myEntities.Groupeusers .Where(gu => !myEntities.Utilisateur.Any(ut => ut.idgroupe == gu.idgroupe)).ToList(); That should work. EDIT: Try that query instead: var query = myEntities.Groupeusers .Where(gu => !myEntities.Utilisateur .SelectMany(ut=>ut.Groupeuser) .Any(gu => gu.Idgroupe == gu.Idgroupe)).ToList(); OR maybe even better: var query = myEntities.GroupeUsers .Except(myEntities.Utilisateur.SelectMany(ut => ut.Groupeuser)) .ToList(); EDIT2: If I understand your … Read more

[Solved] Check whether a string is in a list at any order in C#

This works for me: Func<string, string[]> split = x => x.Split(new [] { ‘#’ }, StringSplitOptions.RemoveEmptyEntries); if (XAll.Any(x => split(x).Intersect(split(S)).Count() == split(S).Count())) { Console.WriteLine(“Your String is exist”); } Now, depending on you you want to handle duplicates, this might even be a better solution: Func<string, HashSet<string>> split = x => new HashSet<string>(x.Split( new [] { … Read more

[Solved] Convert SQL Query To LINQ?

I didn’t test it, but it should look something like that : var query = (from s in Suppliers select new { SupplierId = s.SupplierId, CompanyName = s.CompanyName, ContactPerson = s.ContactPerson, Address = s.Address, Email = s.Email, InActive = s.InActive, BranchId = s.BranchId, CreateDate = s.CreateDate, CreatedBy = s.CreatedBy, UpdateDate = s.UpdateDate, UpdateBy = s.UpdatedBy, … Read more

[Solved] Quick way to compare arrays with LINQ

Based on Nacho’s idea, this is my solution (not ideal, but I’ll take it for now): [TestCase(new int[] { 0, 1, 2, 3 }, true)] [TestCase(new int[] { 0, 3, 4 }, false)] [TestCase(new int[] { 4, 4, 4 }, true)] [TestCase(new int[] { 6, 6, 8, 8 }, true)] [TestCase(new int[] { 5, 4, … Read more

[Solved] How I can Convert T-SQL to Linq C#

surecModel = Surecler.Select(s=> new { s.SurecId , s.Damga}) .Distinct() // .Join( db.WEB_SURECROL.DefaultIfEmpty(), SURECDAMGALAR => SURECDAMGALAR.SurecId, SURECROLLER => SURECROLLER.SurecID, (SURECDAMGALAR, SURECROLLER) => new { SURECDAMGALAR, SURECROLLER }) // .GroupJoin(Surecler.DefaultIfEmpty(), surecTanim => new { surecTanim.SURECDAMGALAR.Damga,surecTanim.SURECROLLER.RolId }, SUREC_LIST => new { SUREC_LIST.Damga,SUREC_LIST.RolId }, (surecTanim,SUREC_LIST) => new {surecTanim,SUREC_LIST } ) // .Select(x=> new { x.surecTanim.SURECROLLER.WEB_SURECTANIM.SurecAdi, x.surecTanim.SURECROLLER.WEB_SURECTANIM.SurecTip, x.SUREC_LIST.FirstOrDefault().Damga, x.SUREC_LIST.FirstOrDefault().OnayDurumu, x.surecTanim.SURECROLLER.WEB_ROL.RolAdi, … Read more

[Solved] C# – optimize logic [closed]

Your question is not well-phrased. If your elem1 or elem2 is a single item you want to compare against, this is pretty easy. Just do a LINQ Where to find the items that match the criteria. Coordinates it = new Coordinates { lat = 5, lon = 5 }; var picked = list.Where(x => Math.Abs(x.lat … Read more

[Solved] Dynamic Compilation NullReferenceException error

The problem was in the class Program Main(){ method = cc.CompileCode(file, “testNamespace”, “Class1”, “webRequest”, true, arguments);} The string classname was not the good one and didn’t pointed to the real document I wanted to compile. The good path was method = cc.CompileCode(file,”testNamespace”, “WebRequest”,”webRequest”, true, arguments);} That’s why the Type type; couldn’t get something instead of … Read more

[Solved] How to break from the loop when adding values to the list object which is distinct from already added values of the list?

You can use Contains status = false; for (var i = 0; i < ids.Count; i++) { if (list.Count > 0 && !list.Contains(ids[i])){ list.Add(ids[i]); //add this, be it duplicate or not status = true; //different element found break; //break if this is not duplicate } else { //do something for duplicate list.Add(ids[i]); //add this, be … Read more

[Solved] How to update database using dictionary with linq

This will let you loop over your dictionary values: foreach (string key in dictionary.Keys) { string value = dictionary[key]; //Now, do something with value, such as add to database } And this will let you find a specific dictionary value: string key = “a_key”; if (dictionary.ContainsKey(key)) { string value = dictionary[key]; //Now do something with … Read more

[Solved] Linq – cast anonymous type to concrete type

Simply create instances of the concrete type (there is no requirement to use an anonymous types in LINQ): var suppliers = SupplierView.Select() .GroupBy(x => x.Name.Substring(0, 1).ToUpper(), (alphanumeric, suppliers) => new AlphanumericSuppliers // concrete { Alphanumeric = alphanumeric, Suppliers = suppliers.OrderBy(x => x.Name).ToList() // * }) .OrderBy(x => x.Alphanumeric); *As mentioned in comments, either change Suppliers … Read more

[Solved] Lambda convert to LINQ

Lambda LINQ is still a link expression. However, the statement should look something like this: var train2 = (from c in db.sample1 join t in db.sample2 on c.CertificateId equals t.CertificateId where c.Year.Value.Year == year && c.TrainingTypeId.Value == trainingTypeId && c.IsApproved.Value && t.EndDate >= DateTime.Now select c).Distinct(); 8 solved Lambda convert to LINQ