[Solved] Print non repeating combinations [closed]

Interesting task. Try following code: List<string> list = Enumerable.Range(1, 6).Select(e => ((char)(‘A’ + e – 1)).ToString()).ToList(); List<string> temp = new List<string>(); int count = list.Count; int total = 1 << list.Count; for (int i = 0; i < total; i++) { int k = i; temp.Clear(); for (int j = 0; j < count; j++) … Read more

[Solved] Convert SQL into LINQ and Lambda

Maybe something like this: var result= ( from s in db.Stands join cp in db.ContractProducts on s.Id equals cp.StandId join p in db.Products on cp.ProductId equals p.Id where s.EventId == 1 group p by p.Description into g select new { Description=g.Key, TotalArea = g.Sum (x =>x.TotalArea) } ).ToList(); Where db is the linqdatacontext 1 solved … Read more

[Solved] What is the equivalent code of SQL query in C# with linq to datatable?

I used this Code and it Worked for me. DataRow row = dt.AsEnumerable().FirstOrDefault (r => (DateTime)r[“date”] == timeToCompare.Date & r.Field<string>(“plannum”) == “0995” & tp >= r.Field<TimeSpan>(“MorningStart”) & tp < r.Field<TimeSpan>(“MorningEnd”)); And then using this to get values : sh_starttime = row[“MorningStart”].ToString(); solved What is the equivalent code of SQL query in C# with linq to … Read more

[Solved] Whats is Linq equivalent for SQL query with OR-joins? [duplicate]

You could also do a cross join with a where condition similar to your inner join condition var q1 = from billMap in tblOfferingBillingBehaviorMapping from lkpBill in tblLookUpBillingBehavior where billMap.LkpBillingBehaviorId == lkpBill.LkpBillingBehaviorId || billMap.LkpBillingBehaviorId =lkpBill.ParentRootId select new { billMap, lkpBill }; solved Whats is Linq equivalent for SQL query with OR-joins? [duplicate]

[Solved] How do display top 5 products from specific category [closed]

First, let’s define what we need. We need a table (view) with these fields: ProductId, ProductName, ProductViewCount, and RootCategoryId. Imagine, the Category table has RootCategoryId field already. Then we can use this query to receive the result: SELECT P.Id AS ‘ProductId’, P.Name AS ‘ProductName’, PVC.ProductViewCount, C.RootCategoryId FROM Category C INNER JOIN ProductCategory PC ON PC.CategoryId … Read more

[Solved] IQueryable with Entity Framework – order, where, skip and take have no effect

You are not using the result of query IQueryable<StammdatenEntityModel> query = dbSet; query = query.OrderByDescending(s => s.CreateDateTime); query = query.Where(s => s.Deleted == false); if(!String.IsNullOrEmpty(keyword)) { query = query.Where(s => s.SerialNumber.Contains(keyword)); //simplified for SO } query = query.Skip(skip); query = query.Take(take); 0 solved IQueryable with Entity Framework – order, where, skip and take have no … Read more

[Solved] Sort a string so I can use it with LINQ

If you are going to be dealing with these objects often then I would definitely make classes to represent them to make it easier to deserialize the JSON strings. If not then you can just roll something quick and dirty. Either way I think you are going to want to use the Json.NET library; it … Read more

[Solved] How to sort matrix column values then rows?

You will need a row comparer. We’ll keep in mind that all rows have same length: public class RowComparer : IComparer<IEnumerable<int>> { public int Compare(IEnumerable<int> x, IEnumerable<int> y) { // TODO: throw ArgumentNullException return x.Zip(y, (xItem, yItem) => xItem.CompareTo(yItem)) .Where(c => c != 0).FirstOrDefault(); } } And use it for sorting: inputRows.Select(r => r.OrderBy(x => … Read more

[Solved] Sort a String Array containing Numbers in linq

That happens because you do a string comparison – you should change that to a int comparison string[] arr = { “3”, “1”, “6”, “10”, “5”, “13” }; var result = arr.OrderBy(int.Parse).ToArray(); 1 solved Sort a String Array containing Numbers in linq

[Solved] convert sql query into lambda expression [closed]

Query expression is much simpler in this case. I don’t recommend you to use lambdas with many joins from l in db.Listing join p in db.Place on l.PlaceId equals p.Id join pb in db.Place on p.ParentPlaceId equals pb.Id join a in db.Address on pb.AddressId equals a.Id where l.Id == 9 select new { UnitNumber = … Read more

[Solved] Checking For null in Lambda Expression

Based on “I am trying to get the null, empty string, and source components out of a List” I assume you mean you want a list with these 3 specific values. var allItems = itemsList .Where(s => string.IsNullOrEmpty(s[Constants.ProductSource]) || s[Constants.ProductSource] == source) .ToList() 2 solved Checking For null in Lambda Expression

[Solved] c# linq to xml subnodes query [closed]

Do you mean something like this: var song = “foo2.mp3”; var number = 2; var query = from x in xd.Root.Elements(“file”) where x.Element(“song”).Value == song from y in x.Elements(“listen”) where (int)y.Element(“number”) == number select y.Element(“data”); Which would give you: solved c# linq to xml subnodes query [closed]