Simply put: LINQ to Entities doesn't know about the conversion from your ID type to a string What is the type of c. ID? Is there any reason why it's one type for ID, but another for ReferenzId?
If at all possible, make them the same type, at which point you won't have a problem any more. I don't know if there are other ways of performing conversions in LINQ to Entities - there may be - but aligning the types would be cleaner By the way, this really looks like it's a join: var query = from c in db. Customers join a in db.
Addresses on c. Id equals a. ReferenzId into addresses select new { Id = c.Id, Addresses = addresses } EDIT: To respond to your comment ToString appears in IntelliSense because the compiler has no real idea what your query is going to mean or how it will be translated.
It's perfectly valid C#, and can generate a valid expression tree - it's just that EF doesn't know how to convert that expression tree into SQL You could try using Convert. ToString(c.Id) instead of just calling c.Id.ToString().
Simply put: LINQ to Entities doesn't know about the conversion from your ID type to a string. What is the type of c. ID?
Is there any reason why it's one type for ID, but another for ReferenzId? If at all possible, make them the same type, at which point you won't have a problem any more. I don't know if there are other ways of performing conversions in LINQ to Entities - there may be - but aligning the types would be cleaner.By the way, this really looks like it's a join: var query = from c in db.
Customers join a in db. Addresses on c.Id equals a. ReferenzId into addresses select new { Id = c.
Id, Addresses = addresses }; EDIT: To respond to your comment - ToString appears in IntelliSense because the compiler has no real idea what your query is going to mean or how it will be translated.It's perfectly valid C#, and can generate a valid expression tree - it's just that EF doesn't know how to convert that expression tree into SQL. You could try using Convert. ToString(c.Id) instead of just calling c.Id.ToString()...
It's a historical database that we are using where a. ReferenzID is indeed a string, the reasons being that it can be joined to an int in one table but a GUID in another. – Edward Tanguay Dec 17 '09 at 10:39 thanks but Convert.
ToString(c. Id) gives us the same error – Edward Tanguay Dec 17 '09 at 10:45 Try converting the other way round? Call new Guid(a.
ReferenzId) instead? – Jon Skeet Dec 17 '09 at 10:55 I doubt the parameterized constructor will work, but I'm thinking that String. Equals or Guid.
Equals might. – Craig Stuntz Dec 17 '09 at 16:09.
LINQ to Entities as far as I understand it (for v1) is very primative. In otherwords it doesn't know how to take the extension method "ToString()" and generate the SQL for it. In LINQ to SQL, it executes the extension method "ToString()" before generating the SQL.
The difference is that LINQ to Entities uses IQueryable instead of IEnumerable. BUT, from what I remember casting should work (because casting is a data type and SQL knows about CAST()). So c.Id.ToString() should really be (string)c.Id (also, make sure it is (string) and not (String)).
One of the downfalls I would say about using Lambda (in Entity Framework) to generate the SQL expression instead of pure LINQ. Keep in mind too, that using CAST on the left side of the equals .
Entity framework would not be able to use tostring in a linq statement because (without quotes):.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.