1

エンティティを CRM にインポートする簡単なアプリケーションを作成しています。このインポート中に、インポートされたエンティティ (カスタム エンティティ) を別の (これもカスタム) エンティティに関連付ける必要があります。

新しいオブジェクトは問題ありませんが、更新しようとすると、インポートされたエンティティに関するすべての関連付けを削除し、インポートされたデータに基づいてそれらを再作成する必要があります。

これどうやってするの?

関連付けられているすべてのエンティティを取得してから、それぞれの関連付けを解除することを考えていましたが、それらの関連付けられたエンティティを取得しようとして行き詰まりました。

これにどのようにアプローチすればよいですか?

4

1 に答える 1

0

Student エンティティがあり、CStudent という名前の別のカスタム エンティティに学生コースをコピーするとします
。次のコードを使用できます。

var scs = Context.new_Student_CourcesSet.Where(x => x.new_courceid == Cource.Id).ToList<new_Student_Cources>();

var removedsc = Context.new_new_CStudent_CourcesSet.Where(x => x.new_cstudentid == CStudent.Id).ToList<new_CStudent_Cources>();

EntityReferenceCollection relatedEntities = new EntityReferenceCollection();
EntityReferenceCollection removedrelatedEntities = new EntityReferenceCollection();
Relationship relationship = new Relationship(new_CStudent_Cources.EntityLogicalName);

if (removedsc != null)
{
    foreach (new_CStudent_Cources c in removedsc )
    {
        RemovedrelatedEntities.Add(new EntityReference(new_Cources.EntityLogicalName, (Guid)ar.new_courcesid));
    }

    Service.Disassociate(CStudent.LogicalName, CStudnetid, relationship, RemovedrelatedEntities);
}

foreach (new_Student_Cources d in scs)
{
    relatedEntities.Add(new EntityReference(new_Cources.EntityLogicalName, (Guid)d.new_courceid));
}

Service.Associate(CStudent.LogicalName, CStudentid, relationship, relatedEntities);
于 2015-04-02T07:04:04.880 に答える