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).
In extbase, how can I find all records that do not have a value in the foreign link column.
I have a model that can relate to a different object. The relation is 1:n and it is called "dayend".
I now create a query like this in the responding repository:
$query->equals("dayend", null);
This does not work, meaning that constraint is completely ignored. The original value in that column is "0". Thus, I also tried
$query->equals("dayend.uid", 0);
However, this throws an error: "Could not determine type of relation."
My goal is to get all objects that are NOT related to any "dayend" object. Any ideas?
I have a legacy database that has a table called Address. Now two other tables can have address information assigned to it. To determine which table it came from, there is a SourceID field. If the SourceID is 1 then it is associated with the first table, if it is 2, it is address information for the second table.
This legacy database doesn't have any foreign key constraints defined on the database, and it cannot be added.
I am wondering if I use Entity Framework to create a model that will have this association. Where table 1 can have an entity that has a navigation to address information (with the condition that the SourceID =1) and same with the second table.
I have tried created a conditional mapping and have it set "When SourceID = 1" I also removed the mapping from the column mapping as the column can only be mapped once. When I try to compile, I get the following error:
Error 3004: Problem in mapping fragments starting at line 683: No mapping specified for properties Address.SourceID in Set Addresses. An Entity with Key (PK) will not round-trip when: Entity is type [Model.Address]
Thanks for your help!
Don't use conditional mapping. Map your address to the entity without SourceID property and create two derived entities from the address entity. Use SourceID as discriminator (TPH inheritance - it works same as conditional mapping but you have multiple entities with different discriminator value). Relate your first and second entity to correct address sub entity.
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.
I'm building an ASP.NET MVC site using the ADO.NET Entity Framework.
I have an entity model that includes these entities, associated by foreign keys:
Report(ID, Date, Heading, Report_Type_ID, etc.)
SubReport(ID, ReportText, etc.) - one-to-one relationship with Report.
ReportSource(ID, Name, Description) - one-to-many relationship with Sub_Report.
ReportSourceType(ID, Name, Description) - one-to-many relationship with ReportSource.
Contact (ID, Name, Address, etc.) - one-to-one relationship with Report_Source.
There is a Create.aspx page for each type of SubReport. The post event method returns a new Sub_Report entity.
Before, in my post method, I followed this process:
Set the properties for a new Report entity from the page's fields.
Set the SubReport entity's specific properties from the page's fields.
Set the SubReport entity's Report to the new Report entity created in 1.
Given an ID provided by the page, look up the ReportSource and set the Sub_Report entity's ReportSource to the found entity.
SaveChanges.
This workflow succeeded just fine for a couple of weeks. Then last week something changed and it doesn't work any more. Now instead of the save operation, I get this Exception:
UpdateException: "Entities in 'DIR2_5Entities.ReportSourceSet'
participate in the 'FK_ReportSources_ReportSourceTypes' relationship.
0 related 'ReportSourceTypes' were found. 1 'Report_Source_Types' is expected."
The debug visualizer shows the following:
The SubReport's ReportSource is set and loaded, and all of its properties are correct.
The Report_Source has a valid ReportSourceType entity attached.
In SQL Profiler the prepared SQL statement looks OK. Can anybody point me to what obvious thing I'm missing?
TIA
Notes:
The Report and SubReport are always new entities in this case.
The Report entity contains properties common to many types of reports and is used for generic queries. SubReports are specific reports with extra parameters varying by type. There is actually a different entity set for each type of SubReport, but this question applies to all of them, so I use SubReport as a simplified example.
I realise I'm late to this, but I had a similar problem and I hacked through it for about 3 hours before I came up with a solution. I'd post code, but it's at home - I can do it later if someone needs it.
Here are some things to check:
Set a breakpoint on the SaveChanges() call and examine the object context in depth. You should see a list of additions and changes to the context. When I first looked, I found that it was trying to add all my related objects rather than just point to them. In your case, the context might be trying to add a new Report_Source_Type.
Related to the previous point, but if you're retrieving the report source, make sure it is being retrieved from the database by its entity key and properly attached to the context. If not, your context might believe it to be a new item and therefore its required relationships won't be set.
From memory, I retrieved my references using the context.GetObjectByKey method, and then explicitly attached those objects to the context using the context.Attach method before assigning them to the properties of my original object.
I got this error because the table didn't have a primary key, it had a FK reference, but no PK.
After adding a PK and updating the model all is well.
Check if your ReportSource was loaded with the NoTracking option or if its EntityState == 'Detached'. If so, that is your problem, it must be loaded in the context.
This tends to happen if your database tables have a 1 - 1 relationship with each other. In your example reportsourceset expects a reportsorttypes with whatever id it is referencing. I have run into this problem when my relationship is linking two primary keys from opposite tables together.
I've got the same error because of new object instance which created "behind the scene" in "Added" state. This was not obvious.
I got this error when I added the new entity to the context but forgot to add the new entity to its parent's collection in the object graph.
For example:
Pet pet = new Pet();
context.Pets.Add(pet);
// forgot this: petOwner.Pets.Add(pet);