Entity Framework system.data.objects.objectquery WHERE statement
-
lundi 12 mars 2012 21:06
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
Toutes les réponses
-
mardi 13 mars 2012 16:14
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.- Marqué comme réponse Sophist4u mardi 13 mars 2012 22:23
-
mardi 13 mars 2012 22:22
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

