2

I have been searching but haven't found anything so far as to a solution for this.

I have 3 conceptual tables:

Case
-------------
CaseId
ExternalCaseId


ExtraField
-------------
ExtraFieldId
Name
Type
RegExValidationString


ExtraFieldRef
--------------
Id
CaseId
ExtraFieldId
Value

With this, I can dynamically create fields for a form and save the given value. The trouble I am having is how to create this relationship with EF using the code first model.

Any help or direction would be greatly appreciated.

Justin
  • 3,337
  • 3
  • 16
  • 27

2 Answers2

2

Not tested, but something like this should work as a starting point on the models:

public class Case
{
   public int CaseId {get;set;}
   public virtual Case ExternalCase {get;set;}
}

public class ExtraField
{
   public int ExtraFieldId {get;set;}
   public String Name {get;set;}
   public String Type {get;set;}
   public String RegexValidationString {get;set;}
   public virtual IEnumerable<ExtraFieldRef> ExtraFieldRefs {get;set;}
}

public class ExtraFieldRef
{
   public int Id {get;set;}
   public virtual Case Case {get; set;}
   public virtual ExtraField {get;set;}
   public int Value {get;set;}
}
Paul
  • 35,689
  • 11
  • 93
  • 122
2

Justin,

I would strongly suggest you search for other posts that have already solved a similar situation. A simple search for me produced this in response to your question: Create Code First Many to Many With Additional Fields

In order that your posts don't get closed or marked down (where-in you lose points), do your self a favor and read the FAQ and abide like "The Dude". You will even earn a badge if you complete each section in the FAQ!

Cheers

Community
  • 1
  • 1
Isaiah Nelson
  • 2,450
  • 4
  • 34
  • 53