i'm working with an existing database, looking to update to asp.net MVC 4. I'm having difficulty creading the models for two of the tables. The Rule and RuleApply table.
I hope to query it using something similar to this:
var rules = db.Rules.Include("RulesApply").Where(t => t.rule_active == 1).ToList();
The RuleApply table has no primary key (it's simply used as a lookup table) - so when I try to compile, I get the error:
EntityType 'RuleApply' has no key defined. Define the key for this EntityType.
Is there any way I can link the Rule.id with the RuleApply.rule_id? Or doe the existing table, have to have a primary key added, to allow me to use EF/Linq etc?
namespace emc.Models
{
public class Rule
{
[Key]
public int id { get; set; }
public int type_id { get; set; }
public int rule_active { get; set; }
public DateTime rule_start { get; set; }
public DateTime rule_end { get; set; }
public virtual ICollection<RuleApply> RulesApply { get; set; }
}
public class RuleApply
{
public int type_id { get; set; }
public int rule_id { get; set; }
public virtual Rule Rule { get; set; }
}
}
Thanks for any advice,
Mark