I'm working on an ASP.Net application which uses a SQL-Server DB and database entities. Further i got three database entities which are dependend on each other. This is the dependency hierarchy:
- Instance (Key: InstanceID)
- CustomField (Key: CustomFieldID, InstanceID)
- CustomFieldData (Keys: CustomFieldDataID, CustomFieldID)
- CustomFieldData_Person (Keys: CustomFieldData_PersonID, CustomFieldDataID)
I can find out the entries from the entity CustomField by this with the InstanceID:
var customFieldEntries = DB_Instance_Singleton.getInstance.CustomField.Where(x => x.InstanceID == instanceId);
Now i want to find out all entries from CustomFieldData_Person which belong to the hierarchy with the InstanceID as key.
In SQL i would write something like this:
SELECT * FROM CustomFieldData_Person WHERE CustomFieldDataID in (
SELECT * FROM CustomFieldData WHERE CustomFieldID in (
SELECT * FROM CustomField WHERE InstanceID = instanceId))
Unfortunately i'm absolutely new to LINQ. So my question is, how can i write such a nested query in LINQ (aacording to the first code example above)?
Thanks in advance!