[Solved] Convert this sql command to c# linq

var query = ( from v in dbContext.UnitFeatureValue join u in dbContext.Unit on v.FK_Unit_ID equals u.ID join t in dbContext.FeatureTitle on v.FK_FeatureTitle_ID equals t.ID where v.FK_Unit_ID == 15 && t.canMoreSelect == 1 select new { v.FK_Unit_ID, u.unitNumber, u.unitTitle, t.featureTitleName, }).Distinct(); 3 solved Convert this sql command to c# linq

[Solved] Convert this sql command to c# linq

Introduction This article will provide a step-by-step guide on how to convert a SQL command to a C# LINQ query. LINQ (Language Integrated Query) is a powerful query language that allows developers to write queries in a more concise and expressive way. It is a great way to simplify complex SQL queries and make them … Read more

[Solved] How to Calculate a Discount In LINQ [closed]

Firstly this code is really starting to need a ViewModel or some other construct that would enable you to decouple your business logic from your UI. Having said that, the quick and dirty answer to get you going, would be to implement an interim linq query and then build your results from that // From … Read more

[Solved] Sort date using lambda expression [closed]

What you’re ordering by here is the distance between the pivot (the birthdate) and each date. Something like this: var sorted = data.OrderBy(date => (birthdate – date).TotalDays); will sort by distance, but put all the after dates first, because the TotalDays will be negative, then the before dates. To avoid that, we need to implement … Read more

[Solved] Linq in dictionary collection [closed]

None of the other answers leverage the lookup-speed of the dictionary: var matches = allBills .Where(dict => dict.billList.ContainsKey(“User”)) .Where(dict => dict.billList[“User”] == “Nick”); 4 solved Linq in dictionary collection [closed]

[Solved] Convert LINQ C# to VB.Net

Here’s a working sample: http://dotnetfiddle.net/LNksSW The reason for the error you’re getting is that you’re missing Imports System.Linq at the top of your file. Dim dt as DataTable = new DataTable dt.Columns.Add(“col1”) dt.Rows.Add(“1000000”) dt.Rows.Add(“0010000”) dt.Rows.Add(“0100000”) Dim result = dt _ .AsEnumerable() _ .Select(Function(r) r.Field(Of String)(0)) _ .Select(Function(s) string.Join(“”, s.Select(Function(x, i) _ If(x = “0”, “0”, … Read more

[Solved] joins on multiple keys in linq [closed]

Try code like this using System.Collections.ObjectModel; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Text.RegularExpressions; namespace ConsoleApplication57 { class Program { static void Main(string[] args) { int employeeId = 113; List<E_JOURNAL> employee = E_JOURNAL.journals.Where(x => x.JOURNALID == employeeId).ToList(); var results = (from j in employee join s in E_ABSENCE.absenses on j.JOURNALID equals s.JOURNALID orderby … Read more

[Solved] how to download gridview in excel in ASP.NET C #, ie How to use group by in datatable

Ugh, be prepared for an accident that makes a mess of your data with this “associated by position” idea I wouldn’t use LINQ for this either var l = new List<string>(); string prev = null; foreach(DataRow r in dt.Rows){ var s = (string)r[“Column1”]; var t = (string)r[“Column2”]; if(s != prev){ l.Add(s); prev = s; } … Read more

[Solved] How to write async linq

Poor man’s async/await await Task.Factory.StartNew(() => PopulateList()); EDIT For those who want to see the usage of it How can i send email one after one in a row? and its follow-up question How do i make that it will send the email only once? 3 solved How to write async linq

[Solved] Count linq statement with joins

Got it. Thanks for the help guys. var fullList= from session in mSessions join testRun in mTestRuns on session.Id equals testRun.SessionId where session.Value.Username.Team == “whatever” select new { testRun.Anything }; int count = fullList.Count(); solved Count linq statement with joins

[Solved] Get object in LINQ expression

You could try collecting every db entry that matches your criteria first public static IEnumerable<string> GetFiles(List<string> srcFiles) { var filePaths = new List<string>(); using (var db = new ContentMgmtContext()) { foreach (var fileInfo in srcFiles.Select(file => new FileInfo(file))) { var matches = db.Files.Where(o => o.FileName.ToLower() == fileInfo.Name.ToLower() || o.FileSize == fileInfo.Length.ToString()) if (matches.Count() > 0) … Read more