简体   繁体   中英

MS Dynamics 365 CRM online - dump entity

I'm a newbie in Dynamics 365. We are using Dynamics 365 CRM online version. I need to dump a couple of entities to our local SQL server.

I've found many examples, but not with the entire entity (including lookup columns).

What is not working for me in this (most relevant) sample:

  1. I need a list of all columns (Do I really need to specify the complete column list in new Contact{}?)

  2. Get lookup values in result instead of IDs (guids)

     `var orgContext = new OrganizationServiceContext(service); // Retrieve the Contact records that we created previously. List<Contact> contacts = (from c in orgContext.CreateQuery<Contact>() where c.Address1_City == "New York" select new Contact { ContactId = c.ContactId, FirstName = c.FirstName, LastName = c.LastName }).ToList<Contact>(); Console.Write("Contacts retrieved, ");'

you can very easily do so with Excel Export feature from Dynamics 365 (CRM)

Simply add all Columns to an advanced find view.

  1. Advanced Find Button

  2. Entity selector (look for)

  3. Edit Columns

  4. Add all Columns to View (see separate picture below for more instructions).

  5. View Results

在此处输入图像描述

在此处输入图像描述

If you have more than 100000 records you might hit the limit.

"We're about to generate your Dynamics 365 data in an Excel file (more than 5000 records). If there are more than 100000 records, only the first 100000 will be exported."

In addition to buypass the 100000 limit you can use Export to Excel Tool from XRM Toolbox which can help you get all the records without any coding.

Though what you're doing is good practice, which is having defined list of attributes being mentioned in select list, you can select all the attributes by using below syntax. It's worth to mention that this will have huge performance impact.

List<Contact> contacts = (from c in orgContext.CreateQuery<Contact>()
                                   where c.Address1_City == "New York"
                                   select c).ToList<Contact>();

Coming to your next question - getting lookup field, for that you can use join . For ex. Getting primary contact lookup from account using below syntax. This uses primary key and foreign key between entities to join.

var accountQuery = from account in context.CreateQuery("account")
                   join contact in context.CreateQuery("contact")
                   on account["primarycontactid"] equals contact["contactid"]
                   where account["name"] ==   "Some Company Name"
                    select new {
                           Name = account["name"],
                           Email = account["emailaddress1"],
                           Manager = contact
                      };

foreach (var account in accountQuery)
{
    Console.WriteLine(account.Name + " is run by: " + account.Manager["fullname"]);
}

Read more

Querying using LINQ is one way, there are other ways like web api, fetchxml and query expression to do the same job. You have to still do capture the last run time of your dumping job and filtering delta data using createdon and modifiedon time stamp greater than last run time stamp.

Needless to say, Activity is the most cumbersome entity involving multiple tables as Activity pointer, Activity party, etc.

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