Let's say that we have two contact entities (the father and the son). I've created a 1:N relation with contact (self referential) and insert the lookup field. When I set the new field to any another contact and try to save, I get this error message:
Error Number: 0x80040386
Error Message: Loop exists in this entity hierarchy.
Error Details: Loop exists in this entity hierarchy.
Source File: Not available
Line Number: Not available
Stack Trace Info: [CrmException: Loop exists in this entity hierarchy.]
à Microsoft.Crm.BusinessEntities.ValidateExtension.CheckLoop(Guid parentId, Guid childId, String baseTableName, String referencedAttributePhysicalName, String referencingAttributePhysicalName, ExecutionContext context)
How can I resolve this? Is there any other way to do it? Thanks.
As Pedro said your error is caused by having a circular reference; for example suppose you have Jane who is linked to Lucy, then you try and link Lucy to Jane, that would cause this error. You can also get this when linking to contacts because of a relatipnship they have with another entity type like account.
Look at using relationships, they allow much more flexability for these types of relationships and could be just what you need.
You can't circular references, check if in your hierarchy you have any node that you reference another node in the same hierarchy, either in different levels. In a self referential you can't have reference to nodes in that hierarchy.
Related
All,
I am building a Power Flow. I am returning an object that has a relationship to another entity.
I want to get some values from the related entity.
I am attemping to use the "Get Record" connector. The returning object returns just the logicalEntityName (in this case "opportunities") but Get Record wants an Entity Name that is the Schema Name ("Working Opportunities").
Big Question: What's the secret to use CDS to get information from a related record in another object?
Little Question: How do I do get the Schema Name?
The logical name will be the same as schema name except some casing difference, ie schema name will have camel casing (first letter of first/second word with capitals, you can notice it clearly in custom entity which will have publisher prefix like new_entityname) and logical name will have pascal casing (all lower case).
You can find the details in XrmToolBox metadata browser or in Solution.
In the below snip, (Logical) Name = Opportunity and Schema Name = Opportunity, also Display Name can be anything and can be changed anytime.
Regarding the related entities, you should use List Records: GetItems_V2 and you can use filter by passing parent record to get related child records. Read more
Could you please share flow screenshot and response to help you with your requirement?
As suggested by Arun you could use List Record and filter query to pass parent record id which will be available from dynamic content.
see below link.
https://crmkeeper.com/2019/08/31/cds-list-records-filter-query-using-flow/
Please mark my answer verified if i were helpful
I have been creating a model where one of my assets have a reference to a specific participant.
When I retrieve my asset using the composer-client API I would like to retrieve the details of the participant being referenced.
In the CTO language document I saw this sentence:
"Relationships must be resolved to retrieve an instance of the object being referenced. The act of resolution may result in null, if the object no longer exists or the information in the relationship is invalid." but it does not describe how to do it.
Can someone please let me know what is the best way to resolve a relationship so that I can retrieve the instance of the object (in this case a participant) that I am pointing to?
You can resolve relationships a couple of ways
Lets say we have an asset Widget that is defined as:
namespace SO
participant Person identified by email {
o String email
}
asset Widget identified by assetId {
o String email
--> Person owner
}
Once you have a Widget asset, you can call Widget.owner.getFullyQualifiedType() which returns the name of the participant registry the owner is in. Then call Widget.owner.getIdentifier() to get the id of the owner in the PersonRegistry, then call PersonRegistry.get(identifier) to get the owner participant
When getting the Widget from the WidgetRegistry, you can call WidgetRegistry.resolve(identifier) to resolve all relationships
Hi I have a question that is braking my mind for some days.
I have my SQL server Database and my C# application.
In the DB I have differemt tables, let me show you a simple ex
Tables:
Person
Relationship
City
Business Rules:
The person are from a City, so the person has IdCity
A person has a relationship with other person, and about that relationship you need to save the starting date.
In other projects I already did something like that, but in this proyect this is not working for me.
When I retrieved with LinQ the information about the person, the city is not coming, and an error appears when I try "person.city.description", for ex.
I try using Include("City") in the linq query, but it didn't work. Besides that, I don't know how to manage the circular reference to the person to person relationship.
One important thing, that I think that can be the problem, is that I rename all the tables from the DataModel, for example, the table in database is called Prd_City, so I change the Name and the Entity Set Name for City in c# project. So in the included I have to use the real table name, in other case the query fail, but if I use the real name nothing happens.
using (var context = new MyContext())
{
List<Person> oPeople = (from p in context.Person.Include("Prd_City")
select p).ToList();
return oPeople ;
}
Any help will be welcome.
Thanks!
"It didn't work" is never a good description of your problem. But from the rest of your question I can infer that Person has a navigation property named "Prd_City", while you expected it to be "City". The thing is: you renamed the entities, but not the navigation properties in the entities.
My advice (for what it's worth): it seems that your work database-first. If you can, change to code-first and manually map the POCO classes to their table names, and properties to their database columns. It may be a considerable amount of work (depending on the size of your data model), but after that you will never run the risk of EF "un-renaming" your entities. Besides, the DbContext API is easier to use than ObjectContext. Currently, it's the preferred EF API.
When validating user input how deep would you go? Let say, that the user provided an ID for a database entity. The ID is valid in form, like integer, long etc. But the Entity does not exist in the database.
Should input validation go that deep?
If the entity doesn't exist then trying to access it propably causes some error or exception during execution. So you can check if the ID is valid or manage exception later.
I'm currently in a situation where I need to delete entities without having access to the associated ObjectContext. I read about identifying relationships and they seem to be exactly what I need: I want to delete an object, once it is no longer referenced by its "parent" object.
I am using Visual Studio 2010 Premium to generate my database from an edmx file. As far as I understand, I need to include the foreign key of my "parent" object in the primary key of my "child" object table. However, I cannot find a way to tell Visual Studio to do this.
Can someone please help me out on this? Am I completely on a wrong path or am I just missing a setting somewhere?
I finally figured it out:
Go to your Child entity and create a scalar property ParentId. Set this property as entity key (making it a primary key, together with your Id property of your Child entity). Next go to your ParentChild relationship and add a referential constraint. Principal for the constraint is your Parent and Dependant is your Child. Dependant property must be the property you just created on your Child (i.e. ParentId). Save everything and you're good to go.
Basically this is described as "scenario 2" in this blog post: http://mocella.blogspot.com/2010/01/entity-framework-v4-object-graph.html
No, you are in the right path. What you need to do is in the EDM designer, after creating your 2 entities (Parent and Child), right click on the Parent Entity and select Add => Association... and then specify Multiplicity and Navigation property names, and click Ok. You'll see that VS create an association in between which will result on a relationship between these 2 table later on when you generate a database from your model.
Do not create a property like ParentID on your Child entity as it will be automatically created by the designer once you create the association.
Furthermore, you can right click on the association in the EDM designer and Select Properties and Select "Cascade" on "End2 OnDelete" option so that the child will be deleted when the parent is deleted.