How to search for the record when the table has a composite primary key?

Asked

Viewed 167 times

2

I have in my database the table t_command_control.

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

If the primary key was simple (only as a field CD_STATION) 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 don’t know how to select.

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);

Browser other questions tagged

You are not signed in. Login or sign up in order to post.