0

I have a database and I'm accessing it via EF.

public partial class Project
{
    public int ProjectID { get; set; }
    public string Name { get; set; }

    public virtual ICollection<ProjectAssets> ProjectAssets { get; set; }
}

public partial class ProjectAssets
{
    public int MappingID { get; set; }
    public int ProjectID { get; set; }
    public int AssetID { get; set; }

    public virtual Project Project { get; set; }
    public virtual Asset Asset { get; set; }
}

public partial class Asset
{
    public int AssetID { get; set; }
    public string Name { get; set; }
    public short Type { get; set; }

    public virtual ICollection<ProjectAssets> ProjectAssets { get; set; }
}

So, my program have only 1 active Project in the time. I want to be able to bind to Project and display as a tree or some other way all Assets and I want to be able to create new Asset or add existing Asset what belongs to other project. If I will use the generated entities I would not be able to manage that all so I need some rules. I've already found good impl. of repositories, but still don't know how to create rules. Do I need to create something like:

public class WorkProject : Project
{
    public WorkProject(Project projject){...}
    WorkAsset CreateAsset(){...}
    void AddAsset(Asset asset){...}
}
Incredible
  • 3,495
  • 8
  • 49
  • 77
Towelie
  • 99
  • 2
  • 10

1 Answers1

0

As far as I understand your question, you want to control the graph of entities which are related to a project object. You can leave the repository layer intact and put another layer (business layer) on top of it to enforce the rules.

Alireza
  • 10,237
  • 6
  • 43
  • 59