score:0
In LINQ to SQL you can use Convert.ToString(obj2.Id)
, but it seems EF doesn't support that (see this thread on MSDN). However, you might be able to use a Model Defined Function.
Update: Since it doesn't seem an EF solution will work, I would just create a SQL View with your int
field converted and whatever other fields you need. Or you could keep your existing entities and just join across a two-column view with the int
and string
IDs. The query optimizer should be able to figure out what you're doing to make the performance impact negligible.
score:0
Finally, I made a view based upon the table, with a new int field holding the converted string, on DB side. Then I mapped my EF entity to the view. It works :)
Sad I didn't find a proper solution on EF side. Hopefully, the 4.0 version will solve this kind of issues.
Anyway, thx for your help.
score:0
Does it help if you use the functional C# syntax instead of the special Linq syntax?
var results = FirstEntity.Join(SecondEntity,
obj => obj.SecondEntityId, obj2 => obj2.Id.ToString(),
(obj, obj2) => new { First = obj, Second = obj2 });
score:2
We typically break something like this up into 2 queries (lack of ToString() in linq to entities support makes me want to harm small children).
var query1 = (from SecondEntity obj2 in context.SecondEntity
select obj2.ID).ToList();
// now we're using linq to objects which does support ToString()
query1 = query1.Select(x => x.ToString());
// mixing linq to entities and linq to objects
var query2 = from FirstEntity obj in context.FirstEneity
join SecondEntity obj2 in query1 on obj.SecondEntityId equals obj2.ID
I'm doing this without VS, so some of the syntax could be wrong and it's not a particularly nice solution, but EF is V1.
Source: stackoverflow.com
Related Query
- Linq 2 Entities : Performing a join on two columns with different types
- LINQ Join On Multiple Columns With Different Data Types
- Concatenating two lists of different types with LINQ
- Difference of two List with different types using LINQ
- Problem with simple join by multiple columns in two tables using linq
- C# LINQ join with conditional where clause on two different data sets
- LINQ to SQL join two tables to select parent table twice based on two different columns from child table
- LINQ Join on multiple columns with different record using extension method syntax
- Using LINQ Except() with two collections of different types
- Using linq to join/union two objects with different columns
- Saved projection expression for re-use in different linq expressions with two source objects
- How to Join two columns from table A with two columns from table B - Linq join MVC
- LINQ JOIN with different data types
- find elements of different types in two lists with common property value, linq variant of two for each loops
- Get different and common items in two arrays with LINQ
- Left join on two Lists and maintain one property from the right with Linq
- how to get all columns from a linq result with a join
- Combining collections of different types with LINQ
- LINQ to SQL and Join two tables with OR clause
- LINQ for comparing two lists with complex entities
- Linq join() - Join two entities and select one
- using linq with join using two where on two tables
- Joining two IQueryable variables of different types together using LINQ
- Using Linq and C#, is it possible to join two lists but with interleaving at each item?
- LINQ to Entities, join two tables, then group and take sums of columns from both tables
- how to join two arrays with linq
- How To Join Tables from Two Different Contexts with LINQ2SQL?
- Get duplicates for two columns with LINQ
- LINQ join query with relational entities
- Only parameterless constructors and initializers are supported in LINQ to Entities in linq join with tuples
More Query from same tag
- c# iterate list to merge item with same field
- How to get the index of element inside nested Lists
- Linq ForEach() not populating fields
- Client proxy is not creating methods
- For Linq Select Statement, how to construct a SubClass in a general way at run time?
- Build where clause from arrays of strings using contains keyword in SQl Server
- EF MVC4 returning null after updating entries in many to many relationship
- Flatten a C# Dictionary of Lists with Linq
- Cannot convert type 'Newtonsoft.Json.Linq.JProperty' to 'Newtonsoft.Json.Linq.JObject'
- C# Entity Framework Linq Query not recognizing new changes
- Dynamic column in where condition
- Consuming JSON content using LINQ/C#
- Joining the min value in LINQ
- Combine two list using Linq and add data as needed from different tables
- C# order a list of alphanumeric numbers
- C# Linq Select Rows Where ID Equals ID in CSV
- Get the number of word occurrences in text
- How to translate this inner join T-SQL into LINQ-to-Entities?
- Expression.Lambda<Func<T,bool>> Says 'T' could not be found
- Error declaration or range of a variable
- LINQ to Objects converting to list to display in gridview
- Returning multiple streams from LINQ query
- Entity Framework and diamond joins
- Enumerable.Except does not use my custom comparer
- Querying using Lambda Expression for exists within a list
- Checkbox updates index mvc
- Can this code be converted into a single linq statement?
- When an Expression<T> is compiled, is it implicitly cached?
- Adding a second Join with LINQ
- How to call a method in the where clause of a LINQ query on a IQueryable object