orion updateContext without type - fiware-orion

I need to make an updateContext of an attribute with a known value but with an unknown type. If we could avoid querying the entity first, it would be great. Is there some way of updating an attribute without knowing its type in advance?

It depends on Orion version. Before 0.17.0, the attribute type was used as part of the attribute identification (along with the attribute name). Thus, you needed to know the attribute type in advance in order to update it in a "safe" way (you could use empty type, which means "any type", but at the risk that other attribute with the same name got unintentionally updated).
However, from 0.17.0 on only the attribute name is used for attribute identification. Thus, you don't need to specify the type in attribute updates. Basically:
If the update includes name, type and value, both the type and value get updated
If the update includes name and value (but not type), the value gets updated. The type is left untouched.

Related

Watson assistant entity created with pattern is not setting the matched value in context variable

I have created a entity which has pattern to match 5 digits only, below is the pattern for that.
^([0-9]{5})*?$
But in the node when I am checking for slots and adding the value into a context variable, it is always taking the value name from entity not the value which user is providing.
Below is the image for the node.
For patterns you need to add the literal suffix.
So change your 5th slot "Check for" to:
#Customer_Id.literal
Without this your context variable only stores the value of the entity found. Which in your case is the same as the entity name.

Use MetdataId to find the Attribute Name of a deleted attribute

When I query the metadata using RetrieveMetadataChangesRequest, the RetrieveMetadataChangesResponse returns EntityMetadata and DeletedMetadata. The DeletedMetadata only returns the MetadataId.
Is there a way to get the metadata for the attribute without knowing the entity? Even just the attribute name would be fine.
RetrieveAttributeRequest I think only works if the attribute exists and if you have the entitylogicalname.
No, the only infomration available is the MetadataId.
Quoting from the SDK:
This collection is a dictionary of GUID values using a
DeletedMetadataFilters as a key. The GUID values represent MetadataId
values of the metadata items.
Looking at another part of the SDK specifically addresses this question:
You will also use DeletedMetadataFilters enumeration as a key to the
RetrieveMetadataChangesResponse.DeletedMetadata to filter the GUID
values found in the RetrieveMetadataChangesResponse.DeletedMetadata
property. When you design a metadata cache you will want to use the
MetadataId for each item so that you can identify deleted metadata
items and remove them.
So as a developer you are expected to populate a cache of metadata of interest to your application. You can query the CRM Metadata to find changes and deletes - but in the case of a delete you are responsible for having collected the metadata in your cache.

Converting Classes in Entity Framework

I'm using EF5 and Code-First.
I have an abstract base class called FooBase. Foo1 and Foo2 both inherit from FooBase. I use EF's mapping configuration based on a Discriminator called Bar. So if Bar = someValue, create Foo1... if Bar is anotherValue, create Foo2.
Since Bar is a discriminator, I don't have access to it as a property on any of the Foo classes.
I now have the need to convert an instance of Foo1 to Foo2. I use reflection and move the properites to the new instance, including Foo1's key value. It's an exact duplicate, except that it is a different type. I change the EntityState to modified and save to the database.
However, the discriminator value in the database is not getting updated. It still remains the same value as if it was still Foo1.
I can guess that since the enitity is only set to modified, EF doesn't bother checking the discriminator.
Does anyone know a way around this?
You cannot change existing instance to another type. Type of the entity associated with key value is immutable. If you want to create Foo2 from Foo1 you need to create a new instance with a new key value and insert it to database. Just modifying will always keep the key and discriminator.
If you seriously need to change the type and keep the key inheritance is not solution for you. Think about the key as equivalent to reference and about discriminator as equivalent to type in .NET - you cannot change type of existing reference.

Something I don't quite understand about Conditional Mappings

In most cases, we can map a field in a table either to a property or we can map it using conditional mapping, but not both. Only exception is if condition is set to Is NotNull, since then we can also map to a column.
a) Is this the reason why we are able to map a DB column only once - namely, if field was allowed to have both a property mapping and a conditional mapping, then property mapping would tell EF to retrieve all table rows, while conditional mapping would tell EF to retrieve only those rows that satisfy the condition?!
b) If my reasoning under a) is correct, then why is field allowed to have both mappings when condition is set to Is NotNull? Why won't that create a conflict?
Thank you
Mapping with condition Is NotNull has special meaning because it requires subsequent change in your model. The mapped property in the model must not be nullable. So your column in the database is nullable, your mapping condition filters all records with null value and your property always receives only records with non-null values. Also you can never assign null to the property.
In case of common condition with value equality this special behaviour is not possible.

Supporting default column values in custom Entity Framework provider

I'm working on a custom entity framework provider and I need to add support for default column values for this provider. When the user uses the entity framework wizard and selects a table that includes columns with default values, those default values are not being populated into the entity designer.
I'm a little lost on where exactly this population should take place. I believe the appropriate place would be in the GetEdmType method override of DbXmlEnabledProviderManifest but I just don't see how to set the default value, if this is the correct place.
Anybody has experience writing EF providers that support default values for table columns? How do you implement this?
I am a bit late to the party but DbXmlEnabledProviderManifest is not the right place for adding default values. The provider manifest describes capabilities of the database engine itself and is specific (and general) to this database engine and not to a given database and/or table. The default value in the provider manifest tells EF what value to use for the given column property if one is not provided by the user (e.g. if the user user does not specify scale or precision for a decimal column the value from provider manifest will be used for scale and/or precision used for this column).
If you want just to insert a default value for a property the easiest way is to set the property that corresponds to the column on your entity to this value in the constructor. This way the user can always set it to a different value but if s/he does not the default value will be sent to the database. For some corner case scenarios where some of the columns in the database do not have corresponding properties on entities you can use DefaultValue attribute on the Property element in SSDL which will be inserted to the database when you add a row. This is especially useful if those properties are not nullable since without telling EF what value should be inserted EF would try inserting null which would obviously fail for non-nullable columns.