简体   繁体   中英

How can i get a entity with sub entities in Entity framework?

i have a question about how to fill a json object to show a entity with sub entities.Thats because i have x that has got detail entity which is called y.

DbSyncScopeDescription scopeDesc = new DbSyncScopeDescription("filtered_customer");

// Definition for Customer. DbSyncTableDescription customerDescription = SqlSyncDescriptionBuilder.GetDescriptionForTable("Sales.Customer", serverConn);

scopeDesc.Tables.Add(customerDescription);

// Definition for CustomerContact, including the list of columns to include. Collection columnsToInclude = new Collection(); columnsToInclude.Add("CustomerId"); columnsToInclude.Add("PhoneType"); DbSyncTableDescription customerContactDescription = SqlSyncDescriptionBuilder.GetDescriptionForTable("Sales.CustomerContact", columnsToInclude, serverConn);

scopeDesc.Tables.Add(customerContactDescription);

Two additional steps should be done:

  1. Add EnableQuery attribute, or Queryable if not the latest version you are using:

    [EnableQuery] public static yx(Guid Id)

  2. Add $expand to the query URL:

    /odata/2012-01/x(guid'xxxx')?$expand=t

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