Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5937307
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T15:31:15+00:00 2026-05-22T15:31:15+00:00

I am using Entity Framework 4.1 code first+MVC3 and the inheritence stratagy that I

  • 0

I am using Entity Framework 4.1 code first+MVC3 and the inheritence stratagy that I use is TPC

I have the following classes

Public Class ObjectBase
    <Key()>
    Public Property Id As Integer

    Public Property Description As String
End Class

Public Class Computer
    Inherits ObjectBase

    Public Property Computername As String
End Class

Public Class Book
    Inherits ObjectBase

    Public Property BookName As String
End Class

Public Class User
    <Key()>
    Public Property Id As Integer

    Public Property Name As String
End Class

Public Class BorrowObject
    <Key()>
    Public Property Id As Integer

    Public Property User As User

    Public Property BorrowedObject as ObjectBase
End Class

Public Class BorrowComputerVM
    <Key()>
    Public Property Id As Integer

    Public Property User As User

    Public Property Computer as Computer
End Class

My questions are:

  1. How do I do a query (using LINQ,
    Entity SQL or other commonly used
    way) to get all BorrowObjects where
    BorrowedObject is of type Computer?
  2. How do I map the result of the query
    to the ViewModel called
    “BorrowComputerVM” (used for
    creating views only used for
    borrowing a Computer).

Question 1 (and question 2) should be very simple, but I have allready spent hours on Google to find an answer with no result at all. The only thing I have found is that you can get all computers in ObjectBase by writing context.ObjectBase.OfType(Of Computer), and that does not help since you cannot write context.BorrowObjects.ObjectBase.OfType(Of Computer)

Please provide code samples in VB.NET (if you can), but more importantly: Please ensure that the codesamples you supply work without hours of modification!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T15:31:16+00:00Added an answer on May 22, 2026 at 3:31 pm

    I write it in C#:

    How do I do a query (using LINQ, Entity SQL or other commonly used way)
    to get all BorrowObjects where
    BorrowedObject is of type
    Computer?

    var list = context.BorrowObjects.Include(b => b.BorrowedObject)
                      .Where(b => b.BorrowedObject is Computer)
                      .ToList();
    

    You can omit the Include if you don’t want to eager load the Computer.

    How do I map the result of the query to the ViewModel called
    “BorrowComputerVM” (used for creating
    views only used for borrowing a
    Computer).

    var list = context.BorrowObjects
                      .Where(b => b.BorrowedObject is Computer)
                      .Select(b => new BorrowComputerVM
                              {
                                  Id = b.Id,
                                  User = b.User,
                                  Computer = b.BorrowedObject as Computer
                              })
                      .ToList();
    

    Includes are not necessary if you project into a new type: User and Computer will be loaded in the BorrowComputerVM also without explicit Include.

    The is and as operators work indeed in LINQ to Entities.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using MVC3 with Entity Framework Code First. I have the following model.
I have developed a project using MVC3 and Code first Entity Framework 4.0 as
I have been using Entity Framework CTP with Code-First as in this tutorial by
I am trying to use MVC3 with the Entity framework with Code First, but
I have a problem with the following Linq query using Entity Framework: from o
I'm using code-first in entity-framework 4, Entity Framework Feature CTP 3 Is it possible
How to declare a one to one relationship using Entity Framework 4 Code First
Is there a way in Entity Framework 4 (using CTP4 and Code First if
I am attempting to add Entity Framework, code first, to an MVC application that's
Using Entity Framework with MVC2, I have a series of date textboxes, that I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.