Hi @Kamal ,
Yes, your Matprop is a variable of HitTest, and HitTest is a collection of entities. Usually in OData, $expand is used when it comes to entity collections, which is like expanding the entity collection. For example, there is a class Category, and then there is an entity collection Product below it:
public class Category
{
public int ID { get; set; }
public string Name { get; set; }
public virtual ICollection<Product> Products { get; set; }
}
public class Product
{
public int ID { get; set; }
public string Name { get; set; }
public decimal Price { get; set; }
[ForeignKey("Category")]
public int CategoryId { get; set; }
public Category Category { get; set; }
[ForeignKey("Supplier")]
public string SupplierId { get; set; }
public virtual Supplier Supplier { get; set; }
}
Since you also have an entity collection Supplier under your Category class, and your command is
GET http://localhost/odata/Categories?$expand=Products
And you get the result:
{
"odata.metadata":"http://localhost/odata/$metadata#Categories",
"value":[
{
"Products":[
{"ID":1,"Name":"Hat","Price":"15.00","CategoryId":1,"SupplierId":"CTSO"},
{"ID":2,"Name":"Scarf","Price":"12.00","CategoryId":1,"SupplierId":"CTSO"},
{"ID":3,"Name":"Socks","Price":"5.00","CategoryId":1,"SupplierId":"FBRK"}
],
"ID":1,
"Name":"Apparel"
},
{
"Products":[
{"ID":4,"Name":"Yo-yo","Price":"4.95","CategoryId":2,"SupplierId":"WING"},
{"ID":5,"Name":"Puzzle","Price":"8.00","CategoryId":2,"SupplierId":"WING"}
],
"ID":2,
"Name":"Toys"
}
]
}
You will find that only the Supplier entity collection is not displayed in the entire category, while the others are displayed. When you want to display this entity collection as well, use commands
GET http://localhost/odata/Categories?$expand=Products,Supplier
When you only need to display the Supplier entity collection and nothing else, you can use the command:
GET http://localhost/odata/Products?$select=Supplier&$expand=Supplier
To sum up, expand means to expand the collection of entities, but if you only use expand, the other properties of the class will be displayed together, and to display only one entity collection, you must use select and expand together. At the same time, you cannot expand and display the entity collection directly with select.
Best Regards
Qi You