You can use Include()
first, then retrieve a single object from the resulting query:
Item item = db.Items
.Include(i => i.Category)
.Include(i => i.Brand)
.FirstOrDefault(x => x.ItemId == id);
More Related Contents:
- ASP.NET MVC – Attaching an entity of type ‘MODELNAME’ failed because another entity of the same type already has the same primary key value
- Why does the EF 6 tutorial use asynchronous calls?
- How to add/update child entities when updating a parent entity in EF
- Validation failed for one or more entities while saving changes to SQL Server Database using Entity Framework
- Filter/Search using Multiple Fields – ASP.NET MVC
- Non-static method requires a target
- Using Asp.Net Identity DataBase first approach
- Implementing Audit Log / Change History with MVC & Entity Framework
- How to do a Bulk Insert — Linq to Entities
- How to group by on 2 child entities and get total of both this child entities?
- LINQ to Entities does not recognize the method ‘System.Web.Mvc.FileResult’
- Questions about Entity Framework Context Lifetime
- The operation cannot be completed because the DbContext has been disposed using MVC 4
- Is Deferred Execution in Asp.net MVC View a very bad thing?
- Entity vs Model vs View Model
- Why is Asp.Net Identity IdentityDbContext a Black-Box?
- Export Model to DataTable
- ASP.NET Identity – Multiple object sets per type are not supported
- How to I apply filter while paginating in Asp.net MVC and entity Framework?
- Set database timeout in Entity Framework
- Only primitive types or enumeration types are supported in this context
- Async PartialView causes “HttpServerUtility.Execute blocked…” exception
- Keyword Not Supported: Metadata
- Entities VS Domain Models VS View Models
- How to create custom additional fields in UserProfile in MVC4
- How should I set up my integration tests to use a test database with Entity Framework?
- Where to convert business model to view model?
- Repository Pattern, POCO, and Business Entities
- MVC 4 – Many-to-Many relation and checkboxes
- .NET Managing Layers Relationships