In Entity Framework 6 code first, what attributes can I add to my C# object model for a 1-1 parent/child relationship while the underlying SQL table relationship is a 1 to many?
Data is split between data common to all customers and data for a specific customer in SQL Server 2012.
It has three entities, a WarehouseBase base entity, WarehouseCustom customer specific data and a customer entity.
The C# object:
Warehouse
{
public Guid ID {get;set;}
public string Name {get;set;}
public string Note {get;set;} //customer specific data
}
Customer
{
public Guid ID {get;set;}
public string Name {get;set;}
}
A customer user would use this workflow:
- Customer views Warehouse XYZ in browser. It should return warehouse XYZ shared data (ID, Name) and the customer specific data (Note).
- Customer edits the note and clicks save button
- Note should be saved to database
An admin would edit and save the WarehouseBase data (Name) but not the customer specific data.
SQL tables:
WarehouseBase
ID : Guid
Name: Nvarchar (255)
WarehouseCustom
ID : Guid
WarehouseBaseID: GUID
CustomerID : GUID
Note : Nvarchar (255)
Customer
ID : Guid
Name : Nvarchar (255)
The system has multiple different concurrent customers using web browser front end connecting to a WebAPI server. The server uses EF6/C# to acccess a SQL Server.
What attributes can be added to the C# model for this?
Already seen:
- One to many relationship: http://www.entityframeworktutorial.net/code-first/configure-one-to-many-relationship-in-code-first.aspx
- How to query one to many and load specific child data: Entity Framework include filter child collection