简体   繁体   中英

EF Table with inheritace but not Abstract?

I want to make three table:

  1. Tasks - that table store informations as Ids, Names, Priority of tasks
  2. TakenTasks - in this table we store user's ID that take tasks with DateTime
  3. EndedTasks - Task that end with DateTime of end

My question is, how to make in EntityFramework Core table TakenTasks and EndedTasks have the same propertys mapped to Tasks table without rewriteing code for Ids of tasks, name of tasks etc?

Tasks table can be build based on abstract Task class because i want to have object of Task in list. What is the best solution for scenerio as i mentioned above?

public class Task 
{
    int Id { get; set; }
    string Name { get; set; }
    Priority Priority { get; set; }
}

public class TakenTask 
{
    string UserId { get; set; }
    DateTime DateOfTaken { get; set; }
}

public class EndedTask 
{
    DateTime DateOfEnd { get; set; }
}

How to store information from Task in TakenTask and EndedTask withotu rewriting propertys from Task and have 3 tables ?

You don't need to duplicate the columns in three tables, use a foreign key from TakenTasks and EndedTasks to Task and you can create a public virtual Task ParentTask{ get; set; } public virtual Task ParentTask{ get; set; } public virtual Task ParentTask{ get; set; } in both TakenTasks and EndedTasks so you can access the Task properties

I think you need 2 tables:

  1. Task
  2. Assign

In Task should have

int Id { get; set; }
string Name { get; set; }
Priority Priority { get; set; }
Status Status { get; set; }

In Assign should have

int TaskId { get; set; }
int UserNameId { get; set; }
DateTime StartDate { get; set; }
DateTime EndDate { get; set; }`

Hope this help

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM