7of9121098
asked on
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<anony moustype#1 >
to system.collection.generic. list<strin g>
List<string> wow = new List<string>();
using (var dc = new MyEntities())
{
wow = (from p in dc.mytable
select new { mycompname = p.COMPANYName }).ToList(); ;
}
the error is cannot implicity convert type system.collection.generic.
to system.collection.generic.
List<string> wow = new List<string>();
using (var dc = new MyEntities())
{
wow = (from p in dc.mytable
select new { mycompname = p.COMPANYName }).ToList(); ;
}
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
I found the solution is was a problem with the name in the Edm function. Thanks for your help.
ASKER
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("MyEntityMode
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.COMPA
}