0
Answer

Linq query to Nlinq i.e. linq to memory

asif shakil

asif shakil

7y
232
1

I tried the specific column and all column using the LINQ and it’s executing fastly. But We are facing issue in NLINQ, when LINQ query is converting to NLINQ query passing as a string i.e. ‘link to memory’ then it is taking infinite time. Kindly help me this issue and please advise me if any other way is there to retrieve data.

The below code is:-

static void Main(string[] args)
{
CrmConnection con = new CrmConnection();

IOrganizationService Service = con.Service("*********.onmicrosoft.com", "*********", "", "https://*****.api.crm8.dynamics.com/");

using (var context = new ServiceContext(Service))
{
NLinqQuery query = new NLinqQuery(@"from c in entityname
join a in address on c.ContactId equals a.PrimaryContactId.Id
select new {
c.FullName,
c.Address1_City,
a.Name,
a.Address1_Name
}");

List<object> n = new List<object>();

LinqToMemory linq = new LinqToMemory(query);
linq.SetParameter("entityname", context.ContactSet);
linq.SetParameter("address", context.AccountSet);

Stopwatch sw = Stopwatch.StartNew();
IList result = linq.List();

Console.WriteLine("Total Count " + result.Count);
sw.Stop();
Console.WriteLine("Time taken: {0}s", sw.Elapsed.Seconds);
}
}