-
Notifications
You must be signed in to change notification settings - Fork 223
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
/odata/Products?$expand=Category not working #70
Comments
Any Suggestion ? |
Hi, I am facing similar issue regarding $expand. While querying "~/odata/Products?$expand=Category" -no records from category are returned. Can anyone please help me? |
@sinhatripti2509 Would you please check whether you enable the Expand() or not? Besides, untyped scenario doesn't support $expand. |
I have tried the solution which you provided but still the navigation
properties are not getting displayed from the collection.
*Problem Statement*: I am creating models dynamically by taking schema
information from sparql remote endpoint (graph db). To create edm models
dynamically, I have taken reference from here
<https://github.com/OData/ODataSamples/tree/master/WebApiCore/DynamicEdmModelCreation>.
Get all , $filter , $count , $top & $select are working fine , but $expand
is not giving expected output. Below i have given an example, GetModel()
, which I have taken reference to create navigation properties. Can there
be issue due to settings in navigation properties??
*GetModel():*
private void AddProductModel(EdmModel model, EdmEntityContainer container)
{
IDictionary<string, EdmEntityType> map = new Dictionary<string,
EdmEntityType>();
EdmEntityType product = new EdmEntityType("ns", "Product");
map.Add("Product", product);
product.AddStructuralProperty("Name",
EdmPrimitiveTypeKind.String);
EdmStructuralProperty key = product.AddStructuralProperty("ID",
EdmPrimitiveTypeKind.Int32);
product.AddKeys(key);
model.AddElement(product);
EdmEntitySet products = container.AddEntitySet("Products",
product);
EdmEntityType detailInfo = new EdmEntityType("ns",
"DetailInfo");
detailInfo.AddKeys(detailInfo.AddStructuralProperty("ID",
EdmPrimitiveTypeKind.Int32));
detailInfo.AddStructuralProperty("Title",
EdmPrimitiveTypeKind.String);
model.AddElement(detailInfo);
EdmEntitySet detailInfos =
container.AddEntitySet("DetailInfos", product);
EdmNavigationProperty detailInfoNavProp =
product.AddUnidirectionalNavigation(
new EdmNavigationPropertyInfo
{
Name = "DetailInfo",
TargetMultiplicity = EdmMultiplicity.One,
Target = detailInfo,
});
products.AddNavigationTarget(detailInfoNavProp, detailInfos);
}
*Controller:*
public EdmEntityObjectCollection Get()
{
// Get entity set's EDM type: A collection type.
ODataPath odataPath = Request.ODataFeature().Path;
var model = DataSourceProvider.GetEdmModel();
IEdmType actualEntityType = odataPath.EdmType;
ODataQueryContext queryContext = new ODataQueryContext(model,
actualEntityType, odataPath);
ODataUriParser uriParser = new ODataUriParser(model, new
System.Uri(odataPath.ToString() + Request.QueryString.ToString(), uriKind:
System.UriKind.Relative));
var actualEntityName =
(odataPath.ToString()).Replace("Collection", string.Empty);
IEdmCollectionType collectionType =
(IEdmCollectionType)odataPath.EdmType;
IEdmEntityTypeReference entityType =
collectionType.ElementType.AsEntity();
// Create an untyped collection with the EDM collection type.
EdmEntityObjectCollection collection = new
EdmEntityObjectCollection(new EdmCollectionTypeReference(collectionType));
ODataQueryParser queryParser = new ODataQueryParser();
queryParser.ODataQueryValidation(uriParser, actualEntityName,
entityType, collection, c);
return collection;
}
*GetData():*
public void Get(IEdmEntityTypeReference entityType,
EdmEntityObjectCollection collection)
{
EdmEntityObject entity = new EdmEntityObject(entityType);
entity.TrySetPropertyValue("Name", "abc");
entity.TrySetPropertyValue("ID", 1);
entity.TrySetPropertyValue("DetailInfo", CreateDetailInfo(88,
"abc_detailinfo", entity.ActualEdmType));
collection.Add(entity);
entity = new EdmEntityObject(entityType);
entity.TrySetPropertyValue("Name", "def");
entity.TrySetPropertyValue("ID", 2);
entity.TrySetPropertyValue("DetailInfo", CreateDetailInfo(99,
"def_detailinfo", entity.ActualEdmType));
collection.Add(entity);
}
in the above program, collection returned by controller holds the primitive
values (Name,Id) as well as navigation property values (DetailInfo) but
some how it is not displaying the detailInfo values after executing the
program.
*Url Request*: ~/odata/Products?$expand=DetailInfo
*Present Output*: {"@odata.context":"http://localhost:
(port)/odata/$metadata#Products","value":[{"Name":"abc","ID":1},{"Name":"def","ID":2}]}
*Expected Output:*
{"@odata.context":"http://localhost:(port)/odata/$metadata#Products","value":[{"Name":"abc","ID":1,
"DetailInfo":{"ID":88,"Title":"abc_detailinfo"}},{"Name":"def","ID":2,
"DetailInfo":{"ID":99,"Title":"def_detailinfo"}}]}
…On Fri, Aug 23, 2019 at 10:38 PM Sam Xu ***@***.***> wrote:
@sinhatripti2509 <https://github.com/sinhatripti2509> Would you please
check whether you enable the Expand() or not?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#70?email_source=notifications&email_token=AMEWJA6W3GOWQHQCYOX4M7DQGAKRLA5CNFSM4E7N62RKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD5AZJ2I#issuecomment-524391657>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AMEWJA62UQAFJVFENNM3IMTQGAKRLANCNFSM4E7N62RA>
.
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
HI!
In "ODataUntypedSample" project, when I tried to get the Product's as well as its Category by using "/odata/Products?$expand=Category" - it didn't return the Category records. Can anyone explain why... Is i am missing something?
[tried both "ODataUntypedSample" as well as "ODataUntypedSample6.x"]
The text was updated successfully, but these errors were encountered: