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: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.
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 });
Source: stackoverflow.com
Related Articles
- Linq 2 Entities : Performing a join on two columns with different types
- LINQ Join On Multiple Columns With Different Data Types
- LINQ Join on multiple columns with different record using extension method syntax
- LINQ JOIN with different data types
- Concatenating two lists of different types with LINQ
- how to get all columns from a linq result with a join
- Combining collections of different types with LINQ
- Difference of two List with different types using LINQ
- LINQ join query with relational entities
- Only parameterless constructors and initializers are supported in LINQ to Entities in linq join with tuples
- Problem with simple join by multiple columns in two tables using linq
- C# Using Linq to join 2 tables with 2 same columns
- Linq with different data types
- Linq left join with multiple columns and default values
- LINQ query on entities with join returning items by category
- Writing a nested join with LINQ to Entities
- LINQ join with multiple conditions of different kind
- Generating efficient LEFT JOIN with COUNT in Linq to Entities
- Linq 2 Left Outer Join With Multiple Columns in second one
- C# LINQ join with conditional where clause on two different data sets
- Join 2 lists on empty strings with Anonymous types in Linq
- LINQ to SQL join two tables to select parent table twice based on two different columns from child table
- LINQ to entities - left join with condition
- Using LINQ Except() with two collections of different types
- LINQ to Entities query with join inside method for use in MVC app
- c# linq join on multiple attributes with different names
- Using linq to join/union two objects with different columns
- LINQ Expressions Creating an Array with different object types
- Linq query Join objects with different data sources?
- Linq to Entities Join -- I don't want anonymous types
- Selecting rows in DataFrame by/after grouping using DataFramesMeta in Julia
- How to use a copy-constructor in a LINQ to Entities query?
- Why do not my LINQ query print out data from the database?
- Turning IEnumerable of struct with inner IEnumerable into single dictionary
- Explicit construction of entity type 'tblpayment' in query is not allowed
- Lambda expressions from sql
- Algorithm in the tag clouds (Calculating)
- Is looping through IQueryable the same as looping through a Datareader with Reader.Read() in C#
- Aggregate values and time using LINQ C#
- Dynamic 'table' name in LINQ to entities
- Efficient List Ordering
- How to compare two lists and find the mismatch them in c#?
- LINQ convert DateTime to string
- IEnumerable<List<T>> to List<T>
- How to sum result in each Table and Round from RoundResult in HomePayerResult
- Show User Specific Events on FullCalendar
- find if there are any null row in left join linq
- Create Dictionary(of Dictionary) using Grouping in Linq
- How to initialize var when it is used for different things in a method
- Select method, changes default ordering of DataTable