Guys, could you provide an example of configurations that allow meta fields "MetaField1" for ecommerce Cart object:
cart0["MetaField1"] = 5; //for example
As I understand I have to declare metafield somehow first to use it in application.
Hello Anatoli, I think this documentation may answer your question:
The answer of David is for the administration/manual approach. You can also do it programmatically, by those API:s
David, Quan, thank you for the answers. David, yes, I have to do it via API.
Quan, I have an issue related to Mediachase.MetaDataPlus.Configurator.MetaClass.AddField - it always adds row with SystemMetaClassId = 0 to MetaField table. But I need to specify the class (otherwise contraints exception about uniqe (Name, SystemMetaClassId) pair is thrown). But I haven't found any methods to specify SystemMetaClassId on creation. Maybe you can recommend something?
You don't have to specify SystemMetaClassId on creation. That should be done automatically. Can you post your code here?
var mc = MetaClass.Load(OrderContext.MetaDataContext, OrderConfiguration.Instance.MetaClasses.ShoppingCartClass.Name);
var metaField = MetaField.Create(MetaDataContext.Instance, metaFieldCreatingParam.Namespace, metaFieldCreatingParam.Name, metaFieldCreatingParam.FriendlyName, metaFieldCreatingParam.Description, metaFieldCreatingParam.MetaDataType, metaFieldCreatingParam.Length, metaFieldCreatingParam.AllowNulls, metaFieldCreatingParam.MultiLanguageValue, metaFieldCreatingParam.AllowSearch, metaFieldCreatingParam.IsEncrypted);
Should this code set SystemMetaClassId field? Possible field SystemMetaClassId is something obsolete, since MetaClassMetaFieldRelation table exists?..
Yes, it should work. The relations between metaclasses and metafields are stored in MetaClassMetaFieldRelation, and I don't see any problem with your code. What's the error you got?
There is no problems with the code if I don't have DisplayName in MetaField table yet, but there is problem that I have already metafiled with Name="DisplayName" and SystemMetaClassId = 0, but let's say it doesn't suit my purposes because of length. Can I create another metafield called "DisplayName" with another length? Is it possible?
So could you please clarify conception a little: now all metafields in MetaField table are "globally" defined? I mean that for example if I need assign DisplayName field to some metaclass and this field already exists in MetaField table, should I use this existent field? I am not able to create another one with other parameters (like length, isNullable, etc) that fits the needs of some concrete metaclass, am I right?
So why not just delete the old Display Name then create a new one? Having two meta fields with same name is not recommended.
Quan, ok, understood. Thank you for the comments.