开发者

How to compare linq query result against textbox.value

I have the following linq query:

var solicitudes = from s in dbContext.Menores
select s.Solicitud.fiExpEmpleado;

The query results are 41 employees' Ids. My question is, how can I compare these 41 elements against the value of a textbox so that i can restrict user registration (if the 开发者_StackOverflowID of the textbox matches with one of the query result the registration is denied)?

Hope your help.


You can write a query that checks whether the value exists:

if (dbContext.Menores.Any(s => s.Solicitud.fiExpEmpleado == someValue))


string text = textbox.Text.Trim();
var solicitudes = (from s in dbContext.Menores
                  where s.FieldToCheck == text
                  select s.Solicitud.fiExpEmpleado).FirstOrDefault();
if (solicitudes != null)
{
    //Deny
}


If solicitudes is being returned as a list of ints you could just to:

int employeeId = Convert.ToInt32(txtMyTextBox.Text);
bool isValidEmployeeId = solicitudes.Any(employeeId);


You don't have to compare all values, just create linq query which query for the value of the textbox, and then count use count method,if count is greater then zero, it means it exits,and you can then deny the user.


Here you go.

   if (dbContext.Menores.Exists(x => x.FieldToCheck == text))
   {
            //deny
   }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜