Open ptrushin opened 2 weeks ago
Did you try:
builder.ComplexType<Properties>().Property(e => e.Property1).Name = "Ware";
Yes i did, result was
{"properties":{"ware":"ware1"}}
but i want the result
{"ware": "ware1"}
without inner object properties
I think you can do like this:
a) Add a new property as follows
public class Main
{
public Properties Properties {get;set;}
+ public string Ware {
+ get => Properties.Property1;
+ set => Properties.Property1 = value;
+ }
...
}
b) Ignore the 'Properties'
builder.EntityType<Main>().IgnoreProperty(e => e.Properties);
a) Ignore the 'Properties', same as above b) Create a new EdmProperty for Edm Type 'Main'.
var builder = ....
EdmModel model = builder.GetEdmModel() as EdmModel;
var mainType = model.SchemaElements.OfType<EdmEntityType>().First(c => c.Name == "Main") as EdmEntityType;
var wareProperty = mainType.AddStructuralProperty("Ware", EdmCoreMode.Instance.GetString(false));
PropertyInfo propert1Info = typeof(Properties).GetProperty("Property1");
model.SetAnnotationValue(wareProperty, new ClrPropertyInfoAnnotation(property1Info));
Some function names maybe not correct. Please let me know if it cannot work.
Thanks. I need second variant, because i dont know property name in compile time. But with your example i get an exception
System.InvalidOperationException: The EDM instance of type '[Main Nullable=True]' is missing the property 'Ware'.
@xuzhg
Thanks. I need second variant, because i dont know property name in compile time. But with your example i get an exception
System.InvalidOperationException: The EDM instance of type '[Main Nullable=True]' is missing the property 'Ware'.
@xuzhg
can you share your repro?
@xuzhg , example - https://github.com/ptrushin/odata-text
1) when /odata/$metadata - all ok
2) but when i try to get data - /odata/Main - i get an exception
The EDM instance of type '[OdataText.Main Nullable=True]' is missing the property 'Ware'
I have
And I want to configure Property1 as Main class property with name Ware. When i try
i get an exception 'MemberExpressions must be bound to the LambdaExpression parameter.'
How can i do this?