简体   繁体   中英

Microsoft Dynamics CRM - Plug-in C# - add record to entity collection

Plug-In, C#, Microsoft Dynamics CRM Online

I want to add a record (let's call it "sampleRecord") to an Entity Collection (let's call it "sampleCollection"), but somehow I can't make it work. I found this solution on the internet, but when I check the total record count via ITracingService, it's still 0.

my solution so far:

EntityCollection sampleCollection = new EntityCollection();
sampleCollection.Entities.Add(sampleRecord);

and that's how I checked the total record count:

tracingService.Trace("total record count: " + sampleCollection.TotalRecordCount.ToString());

Thanks in advance for any help!

You're looking at the wrong value. TotalRecordCount is a result from the query execution (not the count of .Entities . If you use .Entities.Count() you should get the correct value, as shown here:

var entityCollection = new EntityCollection();

Console.WriteLine(entityCollection.Entities.Count()); // 0

entityCollection.Entities.Add(new Entity());

Console.WriteLine(entityCollection.Entities.Count()); // 1

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM