How can I get the database schema of a EdmType - entity-framework

Given an instance of EdmType, how do I get the database schema of the corresponding table?
I could find a property for the table name (of course), but nothing for the schema.
I looked at the properties and meta data. Nothing.
Am I missing something?

EdmType doesn't contain such information. You need instance of EntitySet from System.Data.Metadata.Edm namespace and search its MetadataProperties collection for MetadataItem with Name == "Schema". The Value property of this item will contain database schema.

Related

Add attribute to multiple created entities with same id pattern

I didn't found in documentation or source code the specifications to add attribute to multiple created entities with same id pattern. Only found the method for add attr to entity one by one (with array), but this method doesn't work (lazy method) when need add attribute to 100+ entities with id pattern (idIot:1, ... , idIot:N).
Any help?
The NGSIv2 method that allows to update several entities at once is POST /v2/op/update. It uses as parameter an array of entities:
entities, an array of entities, each entity specified using the JSON entity representation format (described in the section "JSON Entity Representation").
and in the cited "JSON Entity Respresentation" section we have:
An entity is represented by a JSON object with the following syntax:
The entity id is specified by the object's id property, whose value is a string containing the entity id.
The entity type is specified by the object's type property, whose value is a string containing the entity's type name.
Entity attributes are specified by additional properties, whose names are the name of the attribute and whose representation is described in the "JSON Attribute Representation" section below. Obviously, id and type are not allowed to be used as attribute names.
Thus, in conclusion, you cannot use a pattern of entities to update.
However, this has an easy workaround: you can create a script (or logical function in a wider program) to do that work, basically:
To query Orion with a given pattern, getting a set of entity (taking into account pagination, if the number of entities is large).
To update all these entities with POST /v2/op/update (taking into account doing it in batches, as there is a limit of 1MB in Orion request, if the number of entities to update is large).
You can have a look to this script, which works in this way (although in this case is to delete a set of entities instead of updating an attribute).

Getting values from relationship attributes in Information Server

I am unable to get the values from Relationship Attributes using the method getAttributeValue().
I understand this function is the traditional way but are there any alternate methods or workarounds?
getAttributeValue() returs database ID of relationship item.
You can use functions below to work with a relationship attribute:
getEntryRelationshipAttrib
String[] Entry::getEntryRelationshipAttrib(String sAttribPath)
Given a relationship attribute path, returns an array of length 2 containing: [0]=Related Item's Catalog's Name, [1]=Related Item's Primary Key, for the related item. Exception will be thrown if attribute sAttribPath doesn't exist or it's not of relationship type
getItemUsingEntryRelationshipAttrib
Item Entry::getItemUsingEntryRelationshipAttrib(String sAttribPath)
return the related item object for given relationship attribute path. Exception will be thrown if attribute sAttribPath doesn't exist or it's not of relationship type

Persisting value objects in Typo3

I've got a Money class that extends AbstractValueObject with the properties $amount (int) and $currency (string). And I've got an AbstractEntity with a $price property holding an instance of Money. How do I get Typo3 to persist that value object? How do I define the mapping?
Coming from Doctrine, I'd expect it to be persisted in two columns price_amount and price_currency.
Extbase does things a bit differently - so value objects needs to be stored in their own tables and relations between objects are stored by using identifiers just like entities.
The only real difference between Entities and VOs is that the persistence manager will use property values (except the identifier field) when looking for VOs for persistence whereas the identifier will be used on Entities.
So you need to add the database schema for the value object to ext_tables.sql and as the table should contain an auto incrementing uid field as well as the fields you need for your VO. Ensure that you create a combined unique index on the amount and currency columns.
Define the TCA mapping and then you can persist value objects either directly if you create a repository or by attaching them to aggregate root objects and persisting these.
The price property on your entity should be an integer in the database schema, as extbase will either store a reference to the uid of the VO (if you only refer to one Money object on your entity) and if you wish to store a collection of Money objects, Extbase will store the number of relations between your entity object and the Money VOs.

How to correctly add a list of objects to database, working with multiple tables?

My database looks like this: Database Diagram MSSMS
So everytime i'm adding a fish to the database, i want to add the fishes's continent, waterlagen and verbanden.
Tables Continenten, Waterlagen & Verbanden are already filled with objects from an array after creating the database.
Im using List Continenten; for example to store multiple continents.
So i tryed:
Vis nieuweVis = new Fish();
nieuweVis.Naam = "Molly";
foreach(Continent c in Continenten)
nieuweVis.Continenten.Add(c)
so in the table VisContinenten
i assume that EF will automaticly fill in the FishId and ContinentId wich are foreignkeys.
I want records in that table also to be unique so i add a unique key to both the columns in VisContinenten so that fish 1 on continent 1 won't appear twice in that table.
Error i get:
An error occurred while saving entities that do not expose foreign key
properties for their relationships
Additional information: Unable to update the EntitySet 'VisContinenten' because it has a DefiningQuery and no element exists in the element to support the current operation.
Help me pls :)
Thank you

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.