logo
down
shadow

How to change the following sql query to Linq query


How to change the following sql query to Linq query

By : user2951564
Date : November 18 2020, 11:13 AM
should help you out How to change the following sql query to Linq query
code :
var inner = from cid in FacebookLikeCategories where cid.UserID = 18 select cid.FacebookLikeCategoryID;
var result = from res in FacebookLikes where inner.Contains(res.UserID) select res.[like];


Share : facebook icon twitter icon
How can i change the following LINQ query as normal sql query

How can i change the following LINQ query as normal sql query


By : user3413629
Date : March 29 2020, 07:55 AM
I hope this helps . Here's the SQL produced by your LINQ query, per LINQPad, where @p0 is the number of rows to Skip:
code :
SELECT [t3].[CustomerID] AS [ID], [t3].[ContactName] AS [Name], (
    SELECT COUNT(*)
    FROM [Customers] AS [t4]
    ) AS [Count]
FROM (
    SELECT [t2].[CustomerID], [t2].[ContactName], [t2].[ROW_NUMBER]
    FROM (
        SELECT ROW_NUMBER() OVER (ORDER BY [t1].[ContactName]) AS [ROW_NUMBER], [t1].[CustomerID], [t1].[ContactName]
        FROM (
            SELECT TOP (10) [t0].[CustomerID], [t0].[ContactName]
            FROM [Customers] AS [t0]
            ORDER BY [t0].[ContactName]
            ) AS [t1]
        ) AS [t2]
    WHERE [t2].[ROW_NUMBER] > @p0
    ) AS [t3]
ORDER BY [t3].[ROW_NUMBER]
How to change sql query left join to linq query

How to change sql query left join to linq query


By : Ricardo
Date : March 29 2020, 07:55 AM
Hope that helps I want to change SQL Server statement to linq. I'm beginner for linq. I need to modify linq statement in my application but I understand the SQL statement. , I converted to Linq with this code.
Thank for all suggestion.
code :
 public IList<OHList> GetValues_Admin(Guid companyID)
{
IList<OHList> tblObj = null;
try
{

    tblObj = (from OH in _entities.tbl_OrderHeader
              join DO in _entities.tbl_DeliveryOrder on OH.ID equals DO.OrderHeaderID into t1
              from t11 in t1.DefaultIfEmpty()
              join IH in _entities.tbl_InvoiceHeader on OH.ID equals IH.OrderHeaderID into t2
              from t22 in t2.DefaultIfEmpty()
              join UA in _entities.tbl_UserAccount on OH.CreatedUserID equals UA.ID                          
              join UP in _entities.tbl_UserProfile on UA.UserProfileID equals UP.ID
              where (OH.Active == true) && (UP.CompanyID == companyID)
              orderby OH.OrderNo descending
              select new OHList 
              {
                  OrderNo = OH.OrderNo,
                  PONo = OH.PONo,
                  CostCenter = OH.CostCenter,
                  ExpectedDeliveryDate = OH.ExpectedDeliveryDate,
                  DeliveryDate = t11.DeliveryDate,
                  PrimaryContactPerson = OH.PrimaryContactPerson ?? "",
                  AlternateContactPerson = OH.AlternateContactPerson ?? "",
                  PrimaryContactNo = OH.AlternateContactNo ?? "",
                  AlternateContactNo = OH.AlternateContactNo ?? "",
                  CreatedDate = OH.CreatedDate,
                  OrderDate = OH.CreatedDate,
                  WaybillNo = OH.WaybillNo,
                  DeliveryStatus = t11.DeliveryStatus,
                  Email = OH.Email ?? "",
                  Address = OH.Address ?? "",
                  PostalCode = OH.PostalCode ?? "",
                  City = OH.City ?? "",
                  Branch = OH.Branch,
                  DONo = t11.DONo,
                  InvoiceNo = t22.InvoiceNo ?? "",
                  IsPaid = (t22.IsPaid == true) ? true : (bool?)null
              }).ToList();
}
catch (Exception ex)
{
    base.Exception(ex);
}
    return tblObj;
}
EntityFramework LINQ query count fails but query returns result. How to optimize LINQ query?

EntityFramework LINQ query count fails but query returns result. How to optimize LINQ query?


By : Milly
Date : March 29 2020, 07:55 AM
This might help you Not quite sure that's the problem, but at least let try to eliminate the potential effect of the so called Parameter Sniffing Problem by eliminating the dateStart / dateEnd parameters by manually building expression with constant values.
First, a little helper method:
code :
using System;
using System.Linq;
using System.Linq.Expressions;

public static class QueryableUtils
{
    public static IQueryable<T> WhereBetween<T>(this IQueryable<T> source, Expression<Func<T, DateTime>> dateSelector, DateTime? startDate, DateTime? endDate)
    {
        if (startDate == null && endDate == null) return source;
        var startCond = startDate != null ? Expression.GreaterThanOrEqual(dateSelector.Body, Expression.Constant(startDate.Value)) : null;
        var endCond = endDate != null ? Expression.LessThanOrEqual(dateSelector.Body, Expression.Constant(endDate.Value)) : null;
        var predicate = Expression.Lambda<Func<T, bool>>(
            startCond == null ? endCond : endCond == null ? startCond : Expression.AndAlso(startCond, endCond),
            dateSelector.Parameters[0]);
        return source.Where(predicate);
    }
}
//if (dateStart.HasValue)
//    query = query.Where(e => e.outer.ValueDate >= dateStart.Value);
//if (dateEnd.HasValue)
//    query = query.Where(e => e.outer.ValueDate <= dateEnd.Value);
query = query.WhereBetween(e => e.outer.ValueDate, dateStart, dateEnd);
To optimize my linq query which listed as top consuming query in azure query performance insight tool

To optimize my linq query which listed as top consuming query in azure query performance insight tool


By : Jamie
Date : March 29 2020, 07:55 AM
To fix the issue you can do Finally i have reduced my query execution time from 55 seconds to on an average 4.5 seconds by removing AsNoTracking().ToList().
Old query which was taken too much time to execute.
code :
  var onlineData = from od in peopleStatuc.AsNoTracking().ToList()
  var onlineData = from od in peopleStats
linq query insert exist query string into linq query

linq query insert exist query string into linq query


By : user2288217
Date : March 29 2020, 07:55 AM
Does that help I want to make the query follow the query string of the website but it cant be done in this way, is there any other option to do something like this? For example i can insert name,type,class in the query string but not every variable is need to search for the student , try this:
code :
        var query = from c in db.Students select c;
        if (Request.QueryString["Name"] != null)
        {
            name = Request.QueryString["Name"];
            query = query.Where(c => c.name == name);
        }

        if (Request.QueryString["Type"] != null)
        {
            type += Request.QueryString["Type"];
            query = query.Where(c => c.type == type);
        }

        GridView1.DataSource = query.ToList()
Related Posts Related Posts :
  • How to do a complex calculation as this sample
  • Passing a ResultSet into a Postgresql Function
  • Netsuite custom formula field using a CASE statement with multiple WHEN conditions returning "invalid expression&qu
  • Execute query command (dynamic sql) runs faster than ordinary query
  • How to extract only numbered rows from a column
  • INSTEAD OF DELETE trigger (Postgresql)
  • Oracle Apex, when a report with sql is created, how do i get it return after entering in to a text box?
  • Select records based on two tables where one column in one table starts with the records from another tables column usin
  • How to write select using two ids combination in Oracle 11g
  • Frequently use of 'UPDATE STATISTICS WITH FULLSCAN' is normal?
  • need query for this simple pulling data sql server
  • Sql query by using decode to show grades of employee
  • Not a single function error in Oracle
  • Oracle SQL optimizer's behavior when dealing with ORs and row-independent predicates (such as functions returning same v
  • Combining output of two or more select statement
  • Must Declare Scalar Variable Exception
  • Postgres Calculate Difference Using Window Functions
  • SQL Server : unsure how to retrieve selected records
  • SQL unique field: concurrency bugs?
  • Query to get the next identity?
  • SQL Server Adding summing values based on the month
  • Join on month if available else join on latest month
  • How to solve error: ORA-01406 fetched column value was truncated?
  • Selecting Field Multiple Times using OR
  • Which SQL datatype can be used to store mobile numbers in numeric forms, without including characters like brackets and
  • Oracle SQL - "Not a group by expression" after adding CASE statements
  • Runnning total of unique string values in column over days
  • VB.Net to AccessDB by SQL - INSERT INTO with parameters error
  • SQL/Excel/VBA - UPDATE query: 'Syntax Error (missing operator) in query expression'
  • Code to combine two sql queries
  • Setting SQL Date field value based off Week Number and Day Number Field
  • SQL query to find matching records but with differences in case sensitivity?
  • How to sort record inside views in SQL Server 2008
  • How to link the output of teradata sql query to an excel sheet?
  • Matching sets in SQL when cross-referencing
  • error even after following Microsoft format in SQL
  • Increase price by percentage, results rounded
  • Can we Use "Case" in a ColdFusion Query-of-Query
  • displaying 'Active' for a row which has 'A' as value
  • Using pattern search in SQL Server Query
  • SQL - how to group transactions for a certain date pattern?
  • How to Index SQL with multiple AND conditions nested inside OR
  • SQL rank with priority
  • Does BigQuery support SubQueries?
  • Any ideas for persisting H2 Database In-Memory mode transaction?
  • How to improve SQL query performance (correlated subqueries)?
  • Filter repeated columns in Oracle
  • SQL Server join on whichever column has value populated
  • use sql stored procedure to insert data which is returned from a query stored in a table
  • Query not working1
  • SQL - using an alias in a where clause in a subquery
  • How to search for a whole word with special char using oracle contains?
  • Production Perfomance of using SELECT * statements?
  • String concatenation not working as expected in SELECT statement
  • How to detect which stored procedures UPDATE or INSERT into a certain TABLE?
  • Select statement inside CASE - SQL
  • .Net Float error 4 - float(4) = 4.44089209850063E-16
  • How to show as column to recursive rows in a table With SQL Server
  • SQL Server error: Column name or number of supplied values does not match table definition
  • How to find a table name which's column name consist cl_
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org