Open katan4ig opened 9 years ago
Can @katan4ig share how the model is defined? and what is the $filter clause?
Model defined into Linq To Entity expression, how it described above.
_exampleRepository.Select(s => new ExampleDto() <= determination new DTO model for each DB item
{
Attributes = new CustomAttribute() <= determination Name Value collection for the Open Type
{
Name = s.Name,
Value = s.Value
}
}
Property "Attributes" initialized into query. Property "DynamicAttributes" from ExampleDto initialized based on "Attributes" property, when API causes him getter.
Result without $filter condition, for example:
[{
Attributes:[
{
Name : "DynamicField1",
Value : "1"
},
{
Name : "DynamicField2",
Value : "2"
},
{
Name : "DynamicField3",
Value : "3"
},
{
Name : "DynamicField4",
Value : "4"
}
],
DynamicField1:"1",
DynamicField2:"2",
DynamicField3:"3",
DynamicField4:"4"
},
{
Attributes:[
{
Name : "DynamicField1",
Value : "5"
},
{
Name : "DynamicField2",
Value : "6"
},
{
Name : "DynamicField3",
Value : "7"
},
{
Name : "DynamicField4",
Value : "8"
}
],
DynamicField1:"5",
DynamicField2:"6",
DynamicField3:"7",
DynamicField4:"8"
}]
Api returned objects with all dynamic properties(Open Types).
Filter condition which thrown exception:
$filter=DynamicField1 eq '1'
Let me know if you need more information. Thanks.
What does the $metadata - model - look like? Query options for dynamic properties support in-memory collection, but is yet to support EF.
$metadata looks like:
<ComplexType Name="ExampleDto" OpenType="true">
<Property Name="Attributes" Type="Collection(Common.DTO.Actions.CustomAttribute)" />
</ComplexType>
EF doesn't support dictionaries, maybe a problem in this.
Im struggling with the same problem. How should you do this?
I'm convert collection to list and work with this in-memory. It's bad way but i didn't found another solution.
"Query options for dynamic properties support in-memory collection, but is yet to support EF."
Are there any plans to support this? We are considering putting collection into memory. But this is really not good!
@congysu please see my comment above.
@xuzhg please see comment above
I store the data for the open types in the database, and I implemented dynamic initialization for them. I'm using the latest version of OData v4 and EF 6.
My model:
"Attributes" field initialization:
This works fine, but if I try to use OData filters, Web API to throw next exception: "Unknown LINQ expression of type 'Index'"
This exception thrown only with filtering by open types. Also, this method work if I use ToList() function before applies Odata filters. But i can't use this way because, if used ToLIst() before filtering then i get all data from DB. This is not a good solution for performance.