none
Entity Framework system.data.objects.objectquery WHERE statement RRS feed

  • Question

  • I am trying to populate a listBox using system.data.objects.objectquery "where" statement.  I have used the following code many times to display content in a list box or combo box:

    lstSources.DataSource = SOMEEntitiesContext.tSourceNames.OrderBy("it.Description")
    lstSources.DisplayMember = "Description"
    lstSources.ValueMember = "SRC_ID"

    The problem with the code above is that I cannot put any parameters on it.  Does someone know I would be able to use the WHERE method to pull data as well?  I am thinking of something like this...however this doesn't work.

    lstSources.DataSource = SOMEEntitiesContext.tSourceNames.Where("it.Disabled" = False).OrderBy("it.Description")
            lstSources.DisplayMember = "Description"
            lstSources.ValueMember = "SRC_ID"

    Thanks in advance.

    Cheers, -Gordon

    Monday, March 12, 2012 9:06 PM

Answers

  • Hi,

    What if you perform something like this:

    lstSources.DataSource = SOMEEntitiesContext.tSourceNames.Where(src => src.Disabled == false).OrderBy(src => src.Description).ToList();
    lstSources.DisplayMember = "Description";
    lstSources.ValueMember = "SRC_ID";

    Best regards,

    JA Reyes.


    Please remember to Vote & "Mark As Answer" if this post is helpful to you.
    Por favor, recuerda Votar y "Marcar como respuesta" si la solución de esta pregunta te ha sido útil.

    • Marked as answer by Sophist4u Tuesday, March 13, 2012 10:23 PM
    Tuesday, March 13, 2012 4:14 PM

All replies

  • Hi,

    What if you perform something like this:

    lstSources.DataSource = SOMEEntitiesContext.tSourceNames.Where(src => src.Disabled == false).OrderBy(src => src.Description).ToList();
    lstSources.DisplayMember = "Description";
    lstSources.ValueMember = "SRC_ID";

    Best regards,

    JA Reyes.


    Please remember to Vote & "Mark As Answer" if this post is helpful to you.
    Por favor, recuerda Votar y "Marcar como respuesta" si la solución de esta pregunta te ha sido útil.

    • Marked as answer by Sophist4u Tuesday, March 13, 2012 10:23 PM
    Tuesday, March 13, 2012 4:14 PM
  • Hi JA,

    Thanks for the reply.  I should have specified that I am using VB.NET.  Your reply got me on the right path to getting this to work.  My quotes should be around the entire query instead of just the entity.

    Here is the solution that I came up with:

    lstSources.DataSource = SOMEntitiesContext.tSourceNames.Where("it.Disabled = False").OrderBy("it.Description")
            lstSources.DisplayMember = "Description"
            lstSources.ValueMember = "SRC_ID"

     Thanks!

    -G

    Tuesday, March 13, 2012 10:22 PM