You must Sign In to post a response.
  • Category: ASP.Net MVC

    How to convert select query to lamda expression in mvc

    my 4 querys are below can any one help me to convert these queries to lamda expression


    select MAX(id) from PAN_UPLOAD where Orgid=1 and Msgtype='PORSP'




    select * from PAN_ORG where Orgcode='PISCAP'

    select * from PAN_ORDRSP_TRK where RspUploadId=775

    select ISNULL(po.ODA063,'kokhoong.wong@sg.panasonic.com'),trk.SellerCode,trk.OrderNum,trk.OrderRspNum from PAN_ORDRSP_TRK trk, PO_AMS po where RspUploadId=775 and po.OrderId=trk.OrderId
  • #768716

    Hi,

    Kindly check and use the following queries and let us know if it works correctly.

    This is just LINQ

    IEnumerable<SelectListItem> stores =
    from PAN_UPLOAD in database.Stores
    where store.Orgcode="PISCAP" //and condition can be added
    select new SelectListItem { Value = store.Name, Text = store.ID,... };//Columns you want

    ViewBag.storeSelector = stores;


    If you want to implement lambda Expression

    IEnumerable<SelectListItem> stores = database.Stores
    .Where(store => store.Orgcode== "PISCAP") //We can and condition
    .Select(store => new SelectListItem { Value = store.Name, Text = store.ID,etc }); // Columns that you need

    ViewBag.storeSelector = stores;


    Kindly check above condition working we can look further for other conditions.


    Thanks,
    Mani

  • #768717
    hi manigandan i want to convert this sql query ( select distinct ISNULL(po.ODA063,'kokhoong.wong@sg.panasonic.com'),trk.SellerCode,trk.OrderNum,trk.OrderRspNum from PAN_ORDRSP_TRK trk, PO_AMS po where RspUploadId=775 and po.OrderId=trk.OrderId) to lamdaexpression query so can u send me

  • #768718


    var query1 = from RspUploadId,OrderId in PO_AMS c
    where RspUploadId =775
    join p in PAN_ORDRSP_TRK on c.OrderId equals p.OrderId
    select (c.ODA063 == null ? null : 'kokhoong.wong@sg.panasonic.com')
    new { Category = c.Name, Name = p.Name };

    Kindly check this code. I don't have sqlserver to test this.


    Thanks,
    Mani

  • #768722
    hi manigandan still now not working i have tried ur query

  • #768724
    Hi,

    Let us know what the issue you are getting. Other's can also help us to sort out this.
    initially we can start with the basic query instead of complex one.

    Like just,

    Select * from TableName

    Then we add Where condition using Lambda and check
    and then we add join condition and finally we add ISNULL functionality

    Thanks,
    Mani

  • #769002
    1.var query=(from n in db.PAN_UPLOAD where n.Orgid=1 && n.Msgtype='PORSP' select max(x=>x.id).first();
    2.var query=(from n in db.PAN_ORG where n.Orgcode='PISCAP' select n).firstordefault();
    2.var query=(from n in db.PAN_ORDRSP_TRK where n. RspUploadId=775 select n).firstordefault();

  • #769032
    You can use the JOIN with Lambda Expression something like given code snippet to to convert select query to lamda expression in mvc
     
    var result = aspnet_Users
    .Join(aspnet_Membership,
    u => u.MyUserId,
    m => m.MyUserId,
    (u, m) => new
    {
    UserName = u.UserName,
    IsApproved = u.IsApproved
    }
    );


Sign In to post your comments