How do I search for the record when the table has composite primary key?

2

I have in my database the table t_command_control .

This table has a composite primary key formed by the CD_STATION and CD_COMMAND fields.

If the primary key was simple (just as CD_STATION field) I would use the expression below to select the record I need.

Entities db = new Entities();
t_command_control objCommandControl = db.t_command_control.FirstOrDefault(e => e.CD_STATION == itCdStation);

But being the composite primary key I do not know how to select.

    
asked by anonymous 30.11.2014 / 18:50

1 answer

2

Lambda expressions can have more than one Boolean expression. In your case, just use the conditional operator E ( && ), leaving the expression as follows:

Entities db = new Entities();

t_command_control objCommandControl = db.t_command_control.FirstOrDefault(e => e.CD_STATION == itCdStation && e.CD_COMMAND == itCdCommand);
    
30.11.2014 / 18:55