Closed lvasiliou closed 3 years ago
I'm not sure what you are trying to do. Can you give a complete example of how you would expect it to work?
Hi I am building an application where metadata is served from an API into a react app that is entity agnostic. So I pass the entity name as param and then I iterate through the entity properties to build a data grid and a new/edit form client-side. This works great so far except I would like to add additional things like the property order etc. Server at this stage is serving additional properties but the client is refusing them. In the JS version of breeze, we were able to pass such additional attributes for the properties using an array of attributes on the property itself.
My own MetaDataProperty: `public class XMetaDataProperty : MetaDataProperty { public string DisplayName { get; set; }
public bool ShowInEditForm { get; set; }
public bool ShowInListView { get; set; }
public bool IsTitle { get; set; }
public int DisplayOrder { get; set; }
public string ToolTip { get; set; }
}`
My attribute to decorate properties server-side:
` [ AttributeUsage(AttributeTargets.Property)] public class ViewAttribute : Attribute { public string DisplayName { get; set; }
public string ToolTip { get; set; }
public int DisplayOrder { get; set; }
public bool ShowInListView { get; set; } = false;
public bool ShowInForm { get; set; } = true;
public bool IsTitle { get; set; } = false;
`
Copy/Pasted the MetadataBuilder from the breeze-server-net project into my own with a small tweak:
` private MetaDataProperty CreateDataProperty(IProperty p) { var dp = new XMetaDataProperty();
var viewAttributes = p.PropertyInfo?.GetCustomAttributes(typeof(ViewAttribute), true);
if (viewAttributes != null && viewAttributes.Length == 1)
{
var viewAttribute = (ViewAttribute)viewAttributes[0];
dp.DisplayName = viewAttribute.DisplayName;
dp.DisplayOrder = viewAttribute.DisplayOrder;
dp.ShowInListView = viewAttribute.ShowInListView;
dp.ShowInEditForm = viewAttribute.ShowInForm;
dp.IsTitle = viewAttribute.IsTitle;
}
` Copy pasted the code from the EFPersistenceManager in breeze-server-net and I override BuildJsonMetadata to use my own MetadataBuilder.
Ah, so you would want your DataProperty to have things like displayName
in addition to the name
, dataType
, isNullable
, etc.
In breeze-client, DataProperty already has a custom
property which is declared as object. So you could have:
{
"name": "firstName",
"dataType": "String",
"isNullable": true,
"custom": {
"displayName": "First Name",
"displayOrder": 1
}
}
The problem is that, right now, the server-side MetaDataProperty doesn't define the Custom
property. Maybe you could add that to your own version:
public class XMetaDataProperty : MetaDataProperty
{
public object Custom { get; set; }
}
Then you can assign a Dictionary to it, or your own class, when you build the metadata. Then breeze-client will be happy, and you can find your properties on the custom
property of the DataProperty.
We'll add the Custom property to MetaProperty in the next release, so you won't need your own subclass.
Server-side Custom
property has been added to MetaProperty
in Breeze.Persistence library in version 5.0.3
Fantastic. I ended up adding it as dynamic to my customisation.
Hi I added custom properties based on a custom attribute to the metadata generated on the server, however, breeze-client errors out as it is not happy with the new data. Is there a way to add my properties to DataProperty?
Unhandled Rejection (Error): Metadata query failed for: https://localhost:44312/api/Data/Metadata. Unable to either parse or import metadata: Error configuring an instance of 'DataProperty'. Unknown property: 'showInEditForm'.; Server side errors encountered - see the entityErrors collection on this object for more detail