score:0
this returns both entities o and od:
var person = (from o in db.persons
join od in db.osobedetails on o.personid equals od.personid
where o.personid == id
select new { persons = o, osebedetails = od }).tolist();
access it something like:
person.persons.personid
or
person.osebedetails.personid
or any other existing property.
score:3
you could have an override of your personviewmodel
constructor that takes a person
object, and set the properties there.
for example, if you had this constructor:
class personviewmodel
{
public personviewmodel(person person)
{
this.personid = person.personid;
this.email = person.email;
// ... other properties set here
}
}
then you could just do:
var person = (from person in db.persons
join od in db.osobedetails
on person.personid equals od.personid
where person.personid == id
select new personviewmodel(person))
.tolist();
Source: stackoverflow.com
Related Query
- LINQ select new model without need of typing every parameter
- Linq - how do I select several fields without using new
- Why does this linq query fail when I change the select clause to select new Model
- Inner Join LINQ Without making a New Model
- LINQ: Select an object and change some properties without creating a new object
- Linq code to select one item
- Return list using select new in LINQ
- Linq select to new object
- Use linq to generate direct update without select
- Entity Framework Select new POCO without .ToList() first
- Linq Select New List Property Null Check
- linq distinct and select new query
- LINQ select to new object, setting values of object in function
- Is there any way to create a LINQ query as a variable without having the data source (yet)?
- LINQ select new class with a name
- LINQ Source Code Available
- Linq to SQL: .FirstOrDefault() not applicable to select new { ... }
- SELECT NEW with a potentially null field using LINQ and Entity Framework
- Select vs Select new in linq
- Linq Select method with a method as a parameter with two parameters
- How to construct IQueryable query using Linq when I just need count without reading all documents in Document-Db database?
- LINQ method to join every n elements in a series by a function, and then re-aggregate those results into a new list?
- Merge duplicate data without affecting others in LINQ code
- Linq with DefaultIfEmpty with select new {}
- Linq to select parent records without children
- Create a Dynamic Linq to EF Expression to Select IQueryable into new class and assign properties
- Need help creating a linq select
- linq - format string from two fields in select new context
- Linq - How Do I select a new object to contain a list of other objects?
- Is there a difference between select new T() and select new T in LINQ
More Query from same tag
- Does Entity Framework perform lambda expressions before or after it fetches the data?
- nested LINQ query, error message
- LINQ naming Standard - Lambda Expression
- LINQ query to Sum value over date ranges
- Convert SQL subquery in Linq
- Trying to retrieve data from multiple related tables in mysql from very big data
- extend linq to entities to recognize custom methods
- Changing value works with eager loading but not lazing loading in linq and ef
- Find all classes with an attribute containing a specific property value
- Linq select distinct values with comparison
- Santax for Joins using Linq/lambda & Nhibernate
- Linq to SQL Strange Caching?
- Do entity framework object references equal for same database objects
- Format LookUp values, retrieved from WebServices
- linq to xml
- LINQ - Dynamic OrderBy in VB.Net
- LINQ: delete from a list elements contained in another list
- LINQ to SQL deployment problem
- Group by dynamic string array keys without anonymous type or strong type
- ASP.net MVC3 entities, don't know how to count
- How can I pass a Predicate<T> to the Where() method in Linq to SQL?
- GetList of records based on list of Id's
- Expression Tree Binary Expression for an 'In' operation
- Linq Group By while avoiding Div/0
- OrderBy Linq with US Dates
- The LINQ expression could not be translated - Entity Framework Core
- How to filter results based on selected results in a LINQ query?
- Remove lines from List<String[]> using Linq, if meeting a certain criteria
- C# Linq to use CellEndEdit of DataGrid to update database
- Recursively Query XML with Linq