Linq To Entities-Anonymous types error...

I get a syntax error on the .ToList() object when I try to reference a anonymous  new field: mycompname,
the error is cannot  implicity convert type system.collection.generic.list<anonymoustype#1>
to system.collection.generic.list<string>

 List<string> wow = new List<string>();
        using (var dc = new MyEntities())
        {
                 wow = (from p in dc.mytable
                  select new { mycompname = p.COMPANYName }).ToList();                  ;
        }
7of9121098Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Snarf0001Commented:
Using new {} creates an anonymous type, just select the member directly.


 List<string> wow = new List<string>();
        using (var dc = new MyEntities())
        {
                 wow = (from p in dc.mytable
                  select p.COMPANYName).ToList();
        }
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
7of9121098Author Commented:
I need to create as a anonymous type because I want to assign it to a user defined function. I got this far.  (In SQL server the user defined function returns a varchar and inputs are varchar and int-2 input values). Therefore I declared them as a string type in the stud function.
therefore this is the error I get.
  The specified method 'System.String fComArray(System.String, Int32)' on the type 'MyFunctions' cannot be translated into a LINQ to Entities store expression.

public static class MyFunctions
 {
   [EdmFunction("MyEntityModel.MyEntity", "fComArray")]
   public static string fComArray(string Companyname, int NumOfYears)
     {throw new NotSupportedException();}
 }  

public class MyResultingType
{
  public string mycompanyname { get; set; }
  public string UDFValue {get;set;}
}

 using (var dc = new MyEntities())
     {
          var items = from p in dc.MyTable select new MyResultingType()
          {   mycompanyname = p.COMPANYNAME, UDFValue= MyFunctions.fComArray  (p.COMPANYNAME,4)};
           
      // I get the error here...as listed above at run-time.
        foreach (var prime in items)
          { Response.Write(prime.COMPANYNAME + "<br>"); }  
      }

0
7of9121098Author Commented:
I found the solution is was a problem with the name in the Edm function. Thanks for your help.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.