locked
Need help with SQL to LINQ conversion RRS feed

  • Question

  • User-501297529 posted

    I'm trying to convert this sql statement to linq and need some assistance:

    Select  
    ul.[id] ,
    ul.[name] ,
    ul.[create_date] ,
    ul.[last_update] ,
    ul.[created_by] ,
    ul.[last_updated_by] ,
    ul.[deleted_by] ,
    ul.[LOCATIONNAME] ,
    ul.[BILLCODECUSTNUMLIST] ,
    ul.[ALLOWRESTORATIONSUBMISSION] ,
    ul.[COMPANYNUMBER] ,
    ul.[ALLOWITEMORDERING] ,
    ul.[ITEMORDEREMAIL] ,
    ul.[GUID]
    FROM USERLOCATION ul,
    MULITCUSTOMERACCESS mca
    where mca.USERID = 'Value'
    and mca.LOCATIONNAME = ul.locationname
    and ul.locationname = 'Value'

    Here is my linq code (usr is WINS_USER table):

    billcodelist = String.Join(",", dc.USERLOCATIONs.Where(f => f.LOCATIONNAME == usr.LOCATION || dc.MULITCUSTOMERACCESSes.Where(d => d.USERID == usr.Name).Select(d => d.LOCATIONNAME).Contains(f.LOCATIONNAME)).Select(f => f.BILLCODECUSTNUMLIST).ToArray());

    I don't know how to combine the two tables in the FROM clause together using LINQ.

    How do I convert that sql to linq, what am I doing incorrectly?

    Monday, November 12, 2018 3:12 PM

Answers

  • User-501297529 posted

    I figured it out.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, November 14, 2018 3:13 PM

All replies

  • User1120430333 posted

    How did the T-SQL even work without a T-SQL  Join on the two tables? 

    A Join on mca.LOCATIONNAME equals ul.locationname Where mca.UserId = value

    Your Linq is nowhere in the ball park in ever working, at least I have never seen such a Linq statement. using a String.Join()

    Monday, November 12, 2018 6:35 PM
  • User1120430333 posted

    Linq 101 shows you how to use a Linq Join.

    https://code.msdn.microsoft.com/101-LINQ-Samples-3fb9811b

    Here is an example of T-SQL Join.

    https://www.tutorialspoint.com/t_sql/t_sql_joining_tables.htm

    Tuesday, November 13, 2018 5:08 PM
  • User-501297529 posted

    I figured it out.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, November 14, 2018 3:13 PM
  • User1120430333 posted

    I figured it out.

    You can't share what you figured out? Maybe, someone else may face a similar problem that you post could help.

    Wednesday, November 14, 2018 6:22 PM
  • User-501297529 posted

    bootzilla

    I figured it out.

    You can't share what you figured out? Maybe, someone else may face a similar problem that you post could help.

    It was a completely different issue then what I posted on here. Had nothing to do with what I posted on here. I basically had to create a new linq query from a different form in the solution.

    Friday, November 16, 2018 8:21 PM