LINQ question

LINQ just doesn't seem to be able to do this, can't understand why, have now created the code in FETCHXML and going to give that a go.

regards,

Matt
 
Im pretty sure it will be able to do it.
Can you give us some more information about what your trying to do?
 
LINQ just doesn't seem to be able to do this, can't understand why, have now created the code in FETCHXML and going to give that a go.

regards,

Matt

It's not that LINQ can't do it per se, it's probably that the query provider for CRM doesn't support it.

Are you aware of how stuff like this works under the covers?
Your LINQ statements are translated into something that CRM understands.
This is done by something called a LINQ Query Provider. When you use LINQ with EntityFramework there is a similar query provider that translates that into stuff EF understands.

It's perfectly possible to use a custom LINQ provider to translate your stuff: http://linqtocrm.codeplex.com/
LINQ is simply the query language that gets translated into provider specific stuff and if you do something that your provider doesn't support then you will run into problems.

Have you been through the documentation to understand what you can and can't do in LINQ to CRM? http://msdn.microsoft.com/en-gb/library/ff681573.aspx
 
Thanks for your replies.

Maybe it's just me expecting too much - I just viewed this as something trivial to do and I can't believe I am getting no where after two days.

Will have a read through the links, thanks for them.

Once again thanks for you time on this.

regards,

Matt
 
Think we have it sorted with LINQ, well early testing appears to work.

Code:
 var retrievedProducts = (from p in orgcontext.ProductSet
                                                 join qd in orgcontext.QuoteDetailSet
                                                 on p.ProductId equals qd.sp_SellingProductId.Id
                                                 where qd.QuoteId.Id == entity.Id
                                                 select new
                                                 {
                                                     product_name = p.orb_ParentProductid
                                                 }).Distinct();

                        var _txttowrite = string.Empty;
                        if (retrievedProducts != null)
                        {
                            // for each item returned write the output to a string.

                            foreach (var item in retrievedProducts)
                            {
                                if (item.product_name != null)
                                {
                                    if (String.IsNullOrEmpty(_txttowrite))
                                    {
                                        _txttowrite = item.product_name.Name;
                                    }
                                    else
                                    {
                                        _txttowrite += ", " + item.product_name.Name;
                                    }
                                }
                            }
                        }

p.orb_ParentProductid is a lookup field and seperating out the null check seems to have cured the problem.

Thanks for everyones help on this.

regards,

Matt
 
Back
Top Bottom