Home c# How to make a LINQ request with Todictionary ()

How to make a LINQ request with Todictionary ()




There are a couple of requests:

string image = product.productcharacteristics
      .Where (C = & GT; c.characteristic.name == "image")
      .Select (C = & GT; C.characteristic.Value)
      .Firstordefault ();
String Price = Product.Productcharacteristics
      .Where (C = & GT; C.characteristic.name == "Price")
      .Select (C = & GT; C.characteristic.Value)
      .Firstordefault ();

I want to do this with one request through a dictionary:

Public Dictionary & Lt; String, String & GT; DICT = p.Productcharacteristics
.Todictionary (C = & GT; C.characteristic.name, C = & GT; C.characteristic.Value)

But nothing comes out, I get a mistake. And so I tried:

Public Dictionary & Lt; String, String & GT; DICT = = Product.Productcharacteristics
        .Select (C = & GT; new {s.characteristic.name, s.characteristic.value})
        .AseNumerable ()
        .Todictionary (C = & GT; S.Name, C = & GT; S.Value)

also error:

Linq to Entities Does Not Recognize The
Method 'System.Collections.Genic.dictionary`2 [System.String, System.String]
TODICTIONARY [& lt; & gt; f__anonymousticpe3`2, string, string]
System.collections.Genic.Ienumerable`1 [& lt; & gt; f__anonymousticpe3`2
System.String, System.String]], System.Func`2 [& lt; & gt; f__anonymousticpe3`2
System.String, System.String], System.String], System.Func`2
& lt; & gt; f__anonymousteype3`2 [System.String, System.String], System.String]) 'Method,
And this Method Cannot Be Translated Into A Store Expression.

How to build a query?

Answer 1, Authority 100%

Try it

DICT = (product.productcharacteristics
       .Asnotracking ()
       .Where (x = & gt; x.characteristic.name == "image")
       .Todictionary (x = & gt; x.name, x = & gt; x.value))
       .Todictionary (S = & GT; S.KEY, S = & GT; S.Value);

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions