score:0
public class Chapter
{
public int Id { get; set; }
...
}
public class PhysicsChapter : Chapter
{
...
}
public class MathsChapter : Chapter
{
...
}
public class SchoolGrade
{
public int Id { get; set; }
public List<Chapter> Chapters { get; set; }
...
}
public class SchoolGradeContext : DbContext
{
public SchoolGradeContext() : base("SchoolGradeContext")
{
}
public DbSet<SchoolGrade> SchoolGrades { get; set; }
public DbSet<Chapter> Chapters { get; set; }
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Entity<Chapter>().Map<PhysicsChapter>(m => m.Requires("ChapterTypeId").HasValue(1));
modelBuilder.Entity<Chapter>().Map<MathsChapter>(m => m.Requires("ChapterTypeId").HasValue(2));
}
}
score:0
public class Chapter
{
public string ChapterName {get; set;}
public string ChapterContent {get; set;}
[ForeignKey("SchoolGrade")]
public Guid SchoolGradeID {get; set;}
}
Source: stackoverflow.com
Related Query
- How to bind and save an object containing a list of objects to database context in ASP.NET MVC with EF code first?
- How to sort list of objects with field containing both words and numbers?
- From a list of objects containing year and decimal, add object with highest decimal for each year to a new list
- How to perform .Max() on a property of all objects in a collection and return the object with maximum value
- Linq query a List of objects containing a list of object
- Using Linq, how to GroupBy against objects in a list within the target object
- How to use Linq to select and group complex child object from a parents list
- How to find how many times the same object appears in a list and then find a property of the most appeared object
- How to get a complement list of objects using linq and EntityFramework
- Group objects in List<T> by id and order the List by duplicateCount for each object
- Group multiple rows containing index and create list of custom objects for each index
- How can I get totals for more than one column in a list and put this into an object using LINQ?
- How to group by a list of objects and declare this list as an attribute of a viewmodel
- Remove objects, and child objects from a list in C# where they match an object property in another list
- How I could loop over an array of objects and add a property from each object to a variable using Linq?
- How to fetch a list from the database based on another list of a different object type?
- How to return List instead of an object using Lambda and EF
- How can I return a object with the sum of all objects from a list using Linq?
- Using LINQ and EF, how to remove values from database where not in list of items
- How to include parent objects list in child entity object
- How to take first N records and add remaining records value in single list object without multiple ToList?
- How to iterate dynamically throught a list of (different) objects and get the value of a specific property?
- How to select object and its properties base on its properties which is list with linq?
- Includes child and child's objects when the child object is not list or collection
- How to run a LINQ query on a collection of objects and a collection inside of each object
- How to query the average from a certain property in an Entity and return it in a List of List of objects in LINQ?
- How to take the Max value from a List of object where the same objects exists with many duplicate rows
- How to Split a object list into sublists grouping by elements(dateTime and String) C#
- Sort Generic list of generic objects by multiple values and specific value of generic object
- How to add Item based on ID to List and Bind to dropdownlist in Asp.net MVC
More Query from same tag
- Creating a Multidimensional array from a list of objects
- How to return a driven collection of [List<>] after filtering by [Where]?
- How to add a list within a list using LINQ
- How to find duplicates in a dynamic list of lists in linq?
- LINQ Group by with multiple values
- Count how many times a field attribute appears in a column
- Get List ordered by number of records from another table using Linq
- Argument type System.Linq.IQueryable<> is not assignable to parameter type Systems.collection.generic.ienumerable
- How to do a Linq Left Outer Join with a middle table?
- Parse complicated XML with c# Xml to linq
- LINQ Sum of entries based on latest date
- Order query Results by Enum Name
- BLToolkit: how to get master-detail result set using LINQ?
- Entity Framework doesn't save
- C# Complex Linq - Join two table within a subquery
- Is possible to change search method in LINQ?
- InsertOnSubmit constraints
- Can't use ternary operator to assign Linq expression
- How can I use C#/LINQ to calculate weighted averages
- Remove duplicate in linq list?
- Selecting all XML elements and their values dynamically using LINQ
- check a List of values in db and retrieve items that fall under a Date Time Month Property
- How to find Row number of an object in a List
- Linq to Entities: see the resulting query (context.Log = Console.Out)
- Creating multiple results from Linq query
- Linq with DynamicObject
- LINQ to SQL Server 2000: "Must declare variable '@p0'"
- DATEDIFF (in months) in linq
- Accessing Linq data in telerik grid ItemCreated method
- Azure Table: How to write a range query to filter on partition key