this will do the trick:
iqueryable<animal> query = from animal in context.animals where animal.animalaliases .any(a => a.alias.contains("userinput")) select animal;
alternatively, you can do it the other way around (start at the
animalalias entity instead of starting at the
iqueryable<animal> query = ( from animalalias in context.animalaliases where animalalias.alias.contains("userinput") select animalalias.animal) .distinct();
i think what you're looking for is just a normal where clause?
var query = from animal in context.animals join animalalias in context.animalaliases on animal.animalid equals animalalias.animalid where animalalias.alias.contains(userinput) select animal;
the alias text is not part of the foreign key relationship - so it shouldn't be in the join.
update - after comments - including from @steven - while the query above is correct and does mimic the original sql - it might be wise to use
distinct() on the output - this will prevent the case where multiple alias matches could occur for a single animal.
var query = (from animal in context.animals join animalalias in context.animalaliases on animal.animalid equals animalalias.animalid where animalalias.alias.contains(userinput) select animal).distinct();
- How to write SQL SELECT INNER JOIN with multiple conditions (with LIKE) query to LINQ to SQL
- How to write a LINQ query with inner join conditions and IN sub query
- write linq similiar where in select from with inner join in sql query
- How to write linq query to match SQL like select top 100 * from tab?
- How to convert a query with inner join in sql to linq
- How to translate SQL statement with multiple join conditions based on subquery to LINQ
- How to write join query with multiple column - LINQ
- How to convert SQL query to LINQ lambda expression with Inner Join and subquery
- LINQ to SQL - Left Outer Join with multiple join conditions
- How do I most elegantly express left join with aggregate SQL as LINQ query
- How to use join with multiple conditions in linq-to-Nhibernate
- How can i write SQL update query with where clause in Entity Framework in C#
- LINQ to Objects: Query with multiple LIKE conditions (OR or AND) possible?
- Convert sql query with multiple inner joins to LINQ
- SQL to nhibernate inner join with sub query and grouping
- How to convert multiple SQL LEFT JOIN statement with where clause to LINQ
- How to write a LINQ query to select from a collection with given set of matching IDs
- How to convert sql inner join query into linq to sql query and convert into list
- LINQ syntax for SQL query with multiple inner joins and aliases
- How to write aggregate query in LINQ reusing part of the select code
- How can i write Linq2Entities Query with inner joins
- Entity Framework Query with multiple join conditions
- How to convert a SQL with multiple left joins to an Entity Framework LINQ statement using Include methods (No Join methods)?
- Select the most recent date in a LINQ query with an inner join
- how to write a Linq query with a EF code first Many to Many relationship
- How do I query SQL Server for a record with multiple key/value pair constraints?
- converting a t-sql query to Linq to Sql with coalesce and multiple join
- How To Write Distance LINQ query i have Lat, Long in table with varchar type SQL Server
- How to query 2 lists with join on multiple columns
- How to select a query with multiple columns and put it into variables using Entity Framework and ASP.NET?
More Query from same tag
- entity framework linq include and grouping
- Specified cast is not valid. Linq DateTime
- Entity Framework Relationships - Preferred Customer Address
- Return 0 if no duplicates found from DistinctBy
- Xpath expression to LINQ expression
- How can I group on a nested property as well as having the same parent in LINQ?
- Are there any performance difference between these 2 linq queries, are they identical or essentially different?
- How to retrieve a single record using a foreign key column in LINQ?
- Error on applying linq to List
- How to select list class properties on the base max value in each group?
- Mapping models with Linq
- Avoiding record duplication in LINQ
- Linq to join two similar object list?
- Linq DataContext SubmitChanges InvalidOperationException from ZombieCheck
- how to parse xml like this using linq to a object
- How to convert xelement to a string in c#?
- LINQ to count items with no occurrences in other entity
- I want to display records of current date in order of pending, solved, cancel
- Get the index of item in list based on value
- searching results of ordered LINQ query
- Linq Select wont retrieve beyond 3 sub levels of object data in EF Core
- Is there a general method to check whether a property define supported by a Linq provider, especially OData?
- Filtering and binding xml data to gridview in Asp.net c#
- What do I replace IQueryable with for Async operations?
- XMLResponse element show in list
- Left Outer Join - LINQ to Datatable
- Best practices to implement Advanced search using linq and Entityframework
- linq `from` clauses between generic and non-generic collections?
- Serializing result of a LINQ IEnumerable
- C# Check if a List is a part of another List