There are two tables in my database, Readsand Alarms. Between the relation Reads(1) and Alarms(many) there is a relation from one to many. For various reasons, the foreign key constraint in the table has Alarmsbeen removed. I cannot restore this restriction. The object Readin my Entity Framework model, therefore, does not have a navigation property Alarms.
I have a boolean property in my class ReadViewModelcalled HasAlarms. I want this to be set to trueif the table Alarmshas at least one row related to Read. I know that if there was a navigation property Alarms, I could do it something like this:
var reads = from read in context.Reads
select new ReadViewModel { . . . };
foreach ( ReadViewModel read in reads ) {
read.HasAlarms = read.Alarms.Any();
}
However, I no longer have the Alarms navigation property. What is the most effective way to do this in my current situation?
Tony
source
share