Selecting multiple columns with linq query and lambda expression












12















I'm new to C# ASP.NET, and am working on my first application.



I'm trying to create a linq statment that return an arrary.



I have a table of products. I want to be able to select name, id, and price, for each product where the status == 1.



I am struggling with crating a way to do this.
I have only been able to return individual items/columns. I have been stuck on this wayyy to long.



This is what I have so far:



try
{
using (UserDataDataContext db = new UserDataDataContext())
{
return db.mrobProducts.Select(x => x.Name).OrderBy(x => x).ToArray();
}
}


If you look in the screen shot below, you can see I have 2 errors,
Select = Type object can not be refered from it's usage
ToArray = cant resolve symbol to array



enter image description here










share|improve this question

























  • You're missing a Where clause, so you're not currently filtering by status. If you're returning multiple columns, have you considered just returning a collection of mrobProduct objects?

    – User
    Aug 10 '14 at 16:47













  • I could not manage to put a where clause in, it would create an error, no matter where or how I was able to add it,

    – Mark
    Aug 10 '14 at 16:54











  • That's unusual. What was the error?

    – User
    Aug 10 '14 at 16:58











  • return a 2 dimensional arrary??

    – Farhad Jabiyev
    Aug 10 '14 at 16:59






  • 1





    Change string to Tuple<int, string, string>

    – Farhad Jabiyev
    Aug 10 '14 at 17:03


















12















I'm new to C# ASP.NET, and am working on my first application.



I'm trying to create a linq statment that return an arrary.



I have a table of products. I want to be able to select name, id, and price, for each product where the status == 1.



I am struggling with crating a way to do this.
I have only been able to return individual items/columns. I have been stuck on this wayyy to long.



This is what I have so far:



try
{
using (UserDataDataContext db = new UserDataDataContext())
{
return db.mrobProducts.Select(x => x.Name).OrderBy(x => x).ToArray();
}
}


If you look in the screen shot below, you can see I have 2 errors,
Select = Type object can not be refered from it's usage
ToArray = cant resolve symbol to array



enter image description here










share|improve this question

























  • You're missing a Where clause, so you're not currently filtering by status. If you're returning multiple columns, have you considered just returning a collection of mrobProduct objects?

    – User
    Aug 10 '14 at 16:47













  • I could not manage to put a where clause in, it would create an error, no matter where or how I was able to add it,

    – Mark
    Aug 10 '14 at 16:54











  • That's unusual. What was the error?

    – User
    Aug 10 '14 at 16:58











  • return a 2 dimensional arrary??

    – Farhad Jabiyev
    Aug 10 '14 at 16:59






  • 1





    Change string to Tuple<int, string, string>

    – Farhad Jabiyev
    Aug 10 '14 at 17:03
















12












12








12


1






I'm new to C# ASP.NET, and am working on my first application.



I'm trying to create a linq statment that return an arrary.



I have a table of products. I want to be able to select name, id, and price, for each product where the status == 1.



I am struggling with crating a way to do this.
I have only been able to return individual items/columns. I have been stuck on this wayyy to long.



This is what I have so far:



try
{
using (UserDataDataContext db = new UserDataDataContext())
{
return db.mrobProducts.Select(x => x.Name).OrderBy(x => x).ToArray();
}
}


If you look in the screen shot below, you can see I have 2 errors,
Select = Type object can not be refered from it's usage
ToArray = cant resolve symbol to array



enter image description here










share|improve this question
















I'm new to C# ASP.NET, and am working on my first application.



I'm trying to create a linq statment that return an arrary.



I have a table of products. I want to be able to select name, id, and price, for each product where the status == 1.



I am struggling with crating a way to do this.
I have only been able to return individual items/columns. I have been stuck on this wayyy to long.



This is what I have so far:



try
{
using (UserDataDataContext db = new UserDataDataContext())
{
return db.mrobProducts.Select(x => x.Name).OrderBy(x => x).ToArray();
}
}


If you look in the screen shot below, you can see I have 2 errors,
Select = Type object can not be refered from it's usage
ToArray = cant resolve symbol to array



enter image description here







c# sql asp.net linq






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Aug 10 '14 at 17:01







Mark

















asked Aug 10 '14 at 16:44









MarkMark

2,99663170




2,99663170













  • You're missing a Where clause, so you're not currently filtering by status. If you're returning multiple columns, have you considered just returning a collection of mrobProduct objects?

    – User
    Aug 10 '14 at 16:47













  • I could not manage to put a where clause in, it would create an error, no matter where or how I was able to add it,

    – Mark
    Aug 10 '14 at 16:54











  • That's unusual. What was the error?

    – User
    Aug 10 '14 at 16:58











  • return a 2 dimensional arrary??

    – Farhad Jabiyev
    Aug 10 '14 at 16:59






  • 1





    Change string to Tuple<int, string, string>

    – Farhad Jabiyev
    Aug 10 '14 at 17:03





















  • You're missing a Where clause, so you're not currently filtering by status. If you're returning multiple columns, have you considered just returning a collection of mrobProduct objects?

    – User
    Aug 10 '14 at 16:47













  • I could not manage to put a where clause in, it would create an error, no matter where or how I was able to add it,

    – Mark
    Aug 10 '14 at 16:54











  • That's unusual. What was the error?

    – User
    Aug 10 '14 at 16:58











  • return a 2 dimensional arrary??

    – Farhad Jabiyev
    Aug 10 '14 at 16:59






  • 1





    Change string to Tuple<int, string, string>

    – Farhad Jabiyev
    Aug 10 '14 at 17:03



















You're missing a Where clause, so you're not currently filtering by status. If you're returning multiple columns, have you considered just returning a collection of mrobProduct objects?

– User
Aug 10 '14 at 16:47







You're missing a Where clause, so you're not currently filtering by status. If you're returning multiple columns, have you considered just returning a collection of mrobProduct objects?

– User
Aug 10 '14 at 16:47















I could not manage to put a where clause in, it would create an error, no matter where or how I was able to add it,

– Mark
Aug 10 '14 at 16:54





I could not manage to put a where clause in, it would create an error, no matter where or how I was able to add it,

– Mark
Aug 10 '14 at 16:54













That's unusual. What was the error?

– User
Aug 10 '14 at 16:58





That's unusual. What was the error?

– User
Aug 10 '14 at 16:58













return a 2 dimensional arrary??

– Farhad Jabiyev
Aug 10 '14 at 16:59





return a 2 dimensional arrary??

– Farhad Jabiyev
Aug 10 '14 at 16:59




1




1





Change string to Tuple<int, string, string>

– Farhad Jabiyev
Aug 10 '14 at 17:03







Change string to Tuple<int, string, string>

– Farhad Jabiyev
Aug 10 '14 at 17:03














4 Answers
4






active

oldest

votes


















24














Not sure what you table structure is like but see below.



public NamePriceModel AllProducts()
{
try
{
using (UserDataDataContext db = new UserDataDataContext())
{
return db.mrobProducts
.Where(x => x.Status == 1)
.Select(x => new NamePriceModel {
Name = x.Name,
Id = x.Id,
Price = x.Price
})
.OrderBy(x => x.Id)
.ToArray();
}
}
catch
{
return null;
}
}


This would return an array of type anonymous with the members you require.



Update:



Create a new class.



public class NamePriceModel 
{
public string Name {get; set;}
public decimal? Price {get; set;}
public int Id {get; set;}
}


I've modified the query above to return this as well and you should change your method from returning string to returning NamePriceModel.






share|improve this answer


























  • The return get's an error, that says: Cant convert expression type Namstring, Pricestring to return type string

    – Mark
    Aug 10 '14 at 16:53













  • @Mark You didn't tell us what you're return type was on the method. Is it string?

    – User
    Aug 10 '14 at 16:58











  • @Mark i'm not sure you have the right return type for the solution you are seeking. You might consider returning dynamic if you aren't interested in creating a type for it. A type would provide more clarity though.

    – scartag
    Aug 10 '14 at 17:00











  • @scaretag, would you be able to provide an example of this based on my updated question?

    – Mark
    Aug 10 '14 at 17:03











  • @Mark i've done that already. i've updated my answer with an example.

    – scartag
    Aug 10 '14 at 17:03



















10














You can use:



public YourClass AllProducts()
{
try
{
using (UserDataDataContext db = new UserDataDataContext())
{
return db.mrobProducts.Where(x => x.Status == 1)
.OrderBy(x => x.ID)
.Select(x => new YourClass { ID = x.ID, Name = x.Name, Price = x.Price})
.ToArray();
}
}
catch
{
return null;
}
}


And here is YourClass implementation:



public class YourClass
{
public string Name {get; set;}
public int ID {get; set;}
public int Price {get; set;}
}


And your AllProducts method's return type must be YourClass.






share|improve this answer

































    3














    using LINQ and Lamba, i wanted to return two field values and assign it to single entity object field;



    as Name = Fname + " " + LName;



    See my below code which is working as expected; hope this is useful;



    Myentity objMyEntity = new Myentity
    {
    id = obj.Id,
    Name = contxt.Vendors.Where(v => v.PQS_ID == obj.Id).Select(v=> new { contact = v.Fname + " " + v.LName}).Single().contact
    }


    no need to declare the 'contact'






    share|improve this answer































      0














              Object AccountObject = _dbContext.Accounts
      .Join(_dbContext.Users, acc => acc.AccountId, usr => usr.AccountId, (acc, usr) => new { acc, usr })
      .Where(x => x.usr.EmailAddress == key1)
      .Where(x => x.usr.Hash == key2)
      .Select(x => new { AccountId = x.acc.AccountId, Name = x.acc.Name })
      .SingleOrDefault();





      share|improve this answer



















      • 1





        could you please Elaborate a Little on your proposed Code?

        – mrk
        Nov 22 '18 at 12:29











      Your Answer






      StackExchange.ifUsing("editor", function () {
      StackExchange.using("externalEditor", function () {
      StackExchange.using("snippets", function () {
      StackExchange.snippets.init();
      });
      });
      }, "code-snippets");

      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "1"
      };
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function() {
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled) {
      StackExchange.using("snippets", function() {
      createEditor();
      });
      }
      else {
      createEditor();
      }
      });

      function createEditor() {
      StackExchange.prepareEditor({
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader: {
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      },
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      });


      }
      });














      draft saved

      draft discarded


















      StackExchange.ready(
      function () {
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f25230829%2fselecting-multiple-columns-with-linq-query-and-lambda-expression%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      4 Answers
      4






      active

      oldest

      votes








      4 Answers
      4






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      24














      Not sure what you table structure is like but see below.



      public NamePriceModel AllProducts()
      {
      try
      {
      using (UserDataDataContext db = new UserDataDataContext())
      {
      return db.mrobProducts
      .Where(x => x.Status == 1)
      .Select(x => new NamePriceModel {
      Name = x.Name,
      Id = x.Id,
      Price = x.Price
      })
      .OrderBy(x => x.Id)
      .ToArray();
      }
      }
      catch
      {
      return null;
      }
      }


      This would return an array of type anonymous with the members you require.



      Update:



      Create a new class.



      public class NamePriceModel 
      {
      public string Name {get; set;}
      public decimal? Price {get; set;}
      public int Id {get; set;}
      }


      I've modified the query above to return this as well and you should change your method from returning string to returning NamePriceModel.






      share|improve this answer


























      • The return get's an error, that says: Cant convert expression type Namstring, Pricestring to return type string

        – Mark
        Aug 10 '14 at 16:53













      • @Mark You didn't tell us what you're return type was on the method. Is it string?

        – User
        Aug 10 '14 at 16:58











      • @Mark i'm not sure you have the right return type for the solution you are seeking. You might consider returning dynamic if you aren't interested in creating a type for it. A type would provide more clarity though.

        – scartag
        Aug 10 '14 at 17:00











      • @scaretag, would you be able to provide an example of this based on my updated question?

        – Mark
        Aug 10 '14 at 17:03











      • @Mark i've done that already. i've updated my answer with an example.

        – scartag
        Aug 10 '14 at 17:03
















      24














      Not sure what you table structure is like but see below.



      public NamePriceModel AllProducts()
      {
      try
      {
      using (UserDataDataContext db = new UserDataDataContext())
      {
      return db.mrobProducts
      .Where(x => x.Status == 1)
      .Select(x => new NamePriceModel {
      Name = x.Name,
      Id = x.Id,
      Price = x.Price
      })
      .OrderBy(x => x.Id)
      .ToArray();
      }
      }
      catch
      {
      return null;
      }
      }


      This would return an array of type anonymous with the members you require.



      Update:



      Create a new class.



      public class NamePriceModel 
      {
      public string Name {get; set;}
      public decimal? Price {get; set;}
      public int Id {get; set;}
      }


      I've modified the query above to return this as well and you should change your method from returning string to returning NamePriceModel.






      share|improve this answer


























      • The return get's an error, that says: Cant convert expression type Namstring, Pricestring to return type string

        – Mark
        Aug 10 '14 at 16:53













      • @Mark You didn't tell us what you're return type was on the method. Is it string?

        – User
        Aug 10 '14 at 16:58











      • @Mark i'm not sure you have the right return type for the solution you are seeking. You might consider returning dynamic if you aren't interested in creating a type for it. A type would provide more clarity though.

        – scartag
        Aug 10 '14 at 17:00











      • @scaretag, would you be able to provide an example of this based on my updated question?

        – Mark
        Aug 10 '14 at 17:03











      • @Mark i've done that already. i've updated my answer with an example.

        – scartag
        Aug 10 '14 at 17:03














      24












      24








      24







      Not sure what you table structure is like but see below.



      public NamePriceModel AllProducts()
      {
      try
      {
      using (UserDataDataContext db = new UserDataDataContext())
      {
      return db.mrobProducts
      .Where(x => x.Status == 1)
      .Select(x => new NamePriceModel {
      Name = x.Name,
      Id = x.Id,
      Price = x.Price
      })
      .OrderBy(x => x.Id)
      .ToArray();
      }
      }
      catch
      {
      return null;
      }
      }


      This would return an array of type anonymous with the members you require.



      Update:



      Create a new class.



      public class NamePriceModel 
      {
      public string Name {get; set;}
      public decimal? Price {get; set;}
      public int Id {get; set;}
      }


      I've modified the query above to return this as well and you should change your method from returning string to returning NamePriceModel.






      share|improve this answer















      Not sure what you table structure is like but see below.



      public NamePriceModel AllProducts()
      {
      try
      {
      using (UserDataDataContext db = new UserDataDataContext())
      {
      return db.mrobProducts
      .Where(x => x.Status == 1)
      .Select(x => new NamePriceModel {
      Name = x.Name,
      Id = x.Id,
      Price = x.Price
      })
      .OrderBy(x => x.Id)
      .ToArray();
      }
      }
      catch
      {
      return null;
      }
      }


      This would return an array of type anonymous with the members you require.



      Update:



      Create a new class.



      public class NamePriceModel 
      {
      public string Name {get; set;}
      public decimal? Price {get; set;}
      public int Id {get; set;}
      }


      I've modified the query above to return this as well and you should change your method from returning string to returning NamePriceModel.







      share|improve this answer














      share|improve this answer



      share|improve this answer








      edited Dec 30 '18 at 21:33









      NinjaFart

      1,38611215




      1,38611215










      answered Aug 10 '14 at 16:48









      scartagscartag

      15.9k33750




      15.9k33750













      • The return get's an error, that says: Cant convert expression type Namstring, Pricestring to return type string

        – Mark
        Aug 10 '14 at 16:53













      • @Mark You didn't tell us what you're return type was on the method. Is it string?

        – User
        Aug 10 '14 at 16:58











      • @Mark i'm not sure you have the right return type for the solution you are seeking. You might consider returning dynamic if you aren't interested in creating a type for it. A type would provide more clarity though.

        – scartag
        Aug 10 '14 at 17:00











      • @scaretag, would you be able to provide an example of this based on my updated question?

        – Mark
        Aug 10 '14 at 17:03











      • @Mark i've done that already. i've updated my answer with an example.

        – scartag
        Aug 10 '14 at 17:03



















      • The return get's an error, that says: Cant convert expression type Namstring, Pricestring to return type string

        – Mark
        Aug 10 '14 at 16:53













      • @Mark You didn't tell us what you're return type was on the method. Is it string?

        – User
        Aug 10 '14 at 16:58











      • @Mark i'm not sure you have the right return type for the solution you are seeking. You might consider returning dynamic if you aren't interested in creating a type for it. A type would provide more clarity though.

        – scartag
        Aug 10 '14 at 17:00











      • @scaretag, would you be able to provide an example of this based on my updated question?

        – Mark
        Aug 10 '14 at 17:03











      • @Mark i've done that already. i've updated my answer with an example.

        – scartag
        Aug 10 '14 at 17:03

















      The return get's an error, that says: Cant convert expression type Namstring, Pricestring to return type string

      – Mark
      Aug 10 '14 at 16:53







      The return get's an error, that says: Cant convert expression type Namstring, Pricestring to return type string

      – Mark
      Aug 10 '14 at 16:53















      @Mark You didn't tell us what you're return type was on the method. Is it string?

      – User
      Aug 10 '14 at 16:58





      @Mark You didn't tell us what you're return type was on the method. Is it string?

      – User
      Aug 10 '14 at 16:58













      @Mark i'm not sure you have the right return type for the solution you are seeking. You might consider returning dynamic if you aren't interested in creating a type for it. A type would provide more clarity though.

      – scartag
      Aug 10 '14 at 17:00





      @Mark i'm not sure you have the right return type for the solution you are seeking. You might consider returning dynamic if you aren't interested in creating a type for it. A type would provide more clarity though.

      – scartag
      Aug 10 '14 at 17:00













      @scaretag, would you be able to provide an example of this based on my updated question?

      – Mark
      Aug 10 '14 at 17:03





      @scaretag, would you be able to provide an example of this based on my updated question?

      – Mark
      Aug 10 '14 at 17:03













      @Mark i've done that already. i've updated my answer with an example.

      – scartag
      Aug 10 '14 at 17:03





      @Mark i've done that already. i've updated my answer with an example.

      – scartag
      Aug 10 '14 at 17:03













      10














      You can use:



      public YourClass AllProducts()
      {
      try
      {
      using (UserDataDataContext db = new UserDataDataContext())
      {
      return db.mrobProducts.Where(x => x.Status == 1)
      .OrderBy(x => x.ID)
      .Select(x => new YourClass { ID = x.ID, Name = x.Name, Price = x.Price})
      .ToArray();
      }
      }
      catch
      {
      return null;
      }
      }


      And here is YourClass implementation:



      public class YourClass
      {
      public string Name {get; set;}
      public int ID {get; set;}
      public int Price {get; set;}
      }


      And your AllProducts method's return type must be YourClass.






      share|improve this answer






























        10














        You can use:



        public YourClass AllProducts()
        {
        try
        {
        using (UserDataDataContext db = new UserDataDataContext())
        {
        return db.mrobProducts.Where(x => x.Status == 1)
        .OrderBy(x => x.ID)
        .Select(x => new YourClass { ID = x.ID, Name = x.Name, Price = x.Price})
        .ToArray();
        }
        }
        catch
        {
        return null;
        }
        }


        And here is YourClass implementation:



        public class YourClass
        {
        public string Name {get; set;}
        public int ID {get; set;}
        public int Price {get; set;}
        }


        And your AllProducts method's return type must be YourClass.






        share|improve this answer




























          10












          10








          10







          You can use:



          public YourClass AllProducts()
          {
          try
          {
          using (UserDataDataContext db = new UserDataDataContext())
          {
          return db.mrobProducts.Where(x => x.Status == 1)
          .OrderBy(x => x.ID)
          .Select(x => new YourClass { ID = x.ID, Name = x.Name, Price = x.Price})
          .ToArray();
          }
          }
          catch
          {
          return null;
          }
          }


          And here is YourClass implementation:



          public class YourClass
          {
          public string Name {get; set;}
          public int ID {get; set;}
          public int Price {get; set;}
          }


          And your AllProducts method's return type must be YourClass.






          share|improve this answer















          You can use:



          public YourClass AllProducts()
          {
          try
          {
          using (UserDataDataContext db = new UserDataDataContext())
          {
          return db.mrobProducts.Where(x => x.Status == 1)
          .OrderBy(x => x.ID)
          .Select(x => new YourClass { ID = x.ID, Name = x.Name, Price = x.Price})
          .ToArray();
          }
          }
          catch
          {
          return null;
          }
          }


          And here is YourClass implementation:



          public class YourClass
          {
          public string Name {get; set;}
          public int ID {get; set;}
          public int Price {get; set;}
          }


          And your AllProducts method's return type must be YourClass.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Aug 10 '14 at 17:10

























          answered Aug 10 '14 at 16:49









          Farhad JabiyevFarhad Jabiyev

          18.6k64076




          18.6k64076























              3














              using LINQ and Lamba, i wanted to return two field values and assign it to single entity object field;



              as Name = Fname + " " + LName;



              See my below code which is working as expected; hope this is useful;



              Myentity objMyEntity = new Myentity
              {
              id = obj.Id,
              Name = contxt.Vendors.Where(v => v.PQS_ID == obj.Id).Select(v=> new { contact = v.Fname + " " + v.LName}).Single().contact
              }


              no need to declare the 'contact'






              share|improve this answer




























                3














                using LINQ and Lamba, i wanted to return two field values and assign it to single entity object field;



                as Name = Fname + " " + LName;



                See my below code which is working as expected; hope this is useful;



                Myentity objMyEntity = new Myentity
                {
                id = obj.Id,
                Name = contxt.Vendors.Where(v => v.PQS_ID == obj.Id).Select(v=> new { contact = v.Fname + " " + v.LName}).Single().contact
                }


                no need to declare the 'contact'






                share|improve this answer


























                  3












                  3








                  3







                  using LINQ and Lamba, i wanted to return two field values and assign it to single entity object field;



                  as Name = Fname + " " + LName;



                  See my below code which is working as expected; hope this is useful;



                  Myentity objMyEntity = new Myentity
                  {
                  id = obj.Id,
                  Name = contxt.Vendors.Where(v => v.PQS_ID == obj.Id).Select(v=> new { contact = v.Fname + " " + v.LName}).Single().contact
                  }


                  no need to declare the 'contact'






                  share|improve this answer













                  using LINQ and Lamba, i wanted to return two field values and assign it to single entity object field;



                  as Name = Fname + " " + LName;



                  See my below code which is working as expected; hope this is useful;



                  Myentity objMyEntity = new Myentity
                  {
                  id = obj.Id,
                  Name = contxt.Vendors.Where(v => v.PQS_ID == obj.Id).Select(v=> new { contact = v.Fname + " " + v.LName}).Single().contact
                  }


                  no need to declare the 'contact'







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Dec 13 '14 at 23:59









                  Muru BakthavachalamMuru Bakthavachalam

                  92487




                  92487























                      0














                              Object AccountObject = _dbContext.Accounts
                      .Join(_dbContext.Users, acc => acc.AccountId, usr => usr.AccountId, (acc, usr) => new { acc, usr })
                      .Where(x => x.usr.EmailAddress == key1)
                      .Where(x => x.usr.Hash == key2)
                      .Select(x => new { AccountId = x.acc.AccountId, Name = x.acc.Name })
                      .SingleOrDefault();





                      share|improve this answer



















                      • 1





                        could you please Elaborate a Little on your proposed Code?

                        – mrk
                        Nov 22 '18 at 12:29
















                      0














                              Object AccountObject = _dbContext.Accounts
                      .Join(_dbContext.Users, acc => acc.AccountId, usr => usr.AccountId, (acc, usr) => new { acc, usr })
                      .Where(x => x.usr.EmailAddress == key1)
                      .Where(x => x.usr.Hash == key2)
                      .Select(x => new { AccountId = x.acc.AccountId, Name = x.acc.Name })
                      .SingleOrDefault();





                      share|improve this answer



















                      • 1





                        could you please Elaborate a Little on your proposed Code?

                        – mrk
                        Nov 22 '18 at 12:29














                      0












                      0








                      0







                              Object AccountObject = _dbContext.Accounts
                      .Join(_dbContext.Users, acc => acc.AccountId, usr => usr.AccountId, (acc, usr) => new { acc, usr })
                      .Where(x => x.usr.EmailAddress == key1)
                      .Where(x => x.usr.Hash == key2)
                      .Select(x => new { AccountId = x.acc.AccountId, Name = x.acc.Name })
                      .SingleOrDefault();





                      share|improve this answer













                              Object AccountObject = _dbContext.Accounts
                      .Join(_dbContext.Users, acc => acc.AccountId, usr => usr.AccountId, (acc, usr) => new { acc, usr })
                      .Where(x => x.usr.EmailAddress == key1)
                      .Where(x => x.usr.Hash == key2)
                      .Select(x => new { AccountId = x.acc.AccountId, Name = x.acc.Name })
                      .SingleOrDefault();






                      share|improve this answer












                      share|improve this answer



                      share|improve this answer










                      answered Nov 22 '18 at 12:22









                      Varun Tej Reddy PutchakayalaVarun Tej Reddy Putchakayala

                      1




                      1








                      • 1





                        could you please Elaborate a Little on your proposed Code?

                        – mrk
                        Nov 22 '18 at 12:29














                      • 1





                        could you please Elaborate a Little on your proposed Code?

                        – mrk
                        Nov 22 '18 at 12:29








                      1




                      1





                      could you please Elaborate a Little on your proposed Code?

                      – mrk
                      Nov 22 '18 at 12:29





                      could you please Elaborate a Little on your proposed Code?

                      – mrk
                      Nov 22 '18 at 12:29


















                      draft saved

                      draft discarded




















































                      Thanks for contributing an answer to Stack Overflow!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f25230829%2fselecting-multiple-columns-with-linq-query-and-lambda-expression%23new-answer', 'question_page');
                      }
                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      404 Error Contact Form 7 ajax form submitting

                      How to know if a Active Directory user can login interactively

                      TypeError: fit_transform() missing 1 required positional argument: 'X'