I am building a website with a rather complex SQL database.
I made a Query class, which holds multiple primitive fields (which all work fine) and also multiple List<SomeType>. SomeType is also defined under the Models folder in my solution. It also holds single instances of SomeType. Then, I made a QueryDBContext class which inherits DbContext.
I have a Generate function which receives a string and creates a fully formed Query instance. If I immediately send it to my View - it works fine. But if I store it in my DB - only the primitive values are kept, and the reference types (both Lists<SomeType> and SomeType) are null.
I believe the problem is that EF doesn't support reference types - or maybe I need something special for this case?
Here's Query
public class Query
{
[Key]
public int id { get; set; }
public SomeType Base { get; set; }
public List<SomeType> Derived { get; set; }
//more of these
public string SmallGraphImage { get; set; }
public string MediumGraphImage { get; set; }
public string LargeGraphImage { get; set; }
}
public class QueriesDBContext : DbContext
{
public DbSet<Query> Queries { get; set; }
}
Here's SomeType
public class SomeType
{
[Key]
public int id { get; set; }
public string ExpandedOutForm { get; set; }
public string ExpandedInForm { get; set; }
//more strings
}
Note: The database works fine for primitives. For developing purposes, I made a Controller which deletes & rebuilds the database for each modification. I also tried replacing List with IList.
If EF doesn't support reference types, what should I do? Will it work on structs ? How can I store Lists inside a database entry? (Yeah, I could store it in another table with its ID - but I believe EF has a more elegant solution for this)