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

  • SEARCH
  • Home
  • 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 8849229
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T12:35:47+00:00 2026-06-14T12:35:47+00:00

I have created a SQL Server view which performs some reasonably complex logic on

  • 0

I have created a SQL Server view which performs some reasonably complex logic on other tables/entities in my model and which exposes a series of columns. All but one of these columns are simple types (bigints, nvarchars etc) but one is a complex entity within my model.

I have created an entity which maps to this view as follows:

public class NetworkSuppliersByClient : Entity, IKeyed<long>
{
    public long NetworkSuppliersByClientId { get; set; }

    public long NetworkId { get; set; }
    public String NetworkName { get; set; }
    public long OwningClientId { get; set; }
    public long ClientId { get; set; }
    public virtual Supplier Supplier { get; set; }
    public bool PublicEntry { get; set; }

    public long GetKey ()
    {
        return NetworkSuppliersByClientId;
    }
}

As you can see, the Supplier entry maps to an existing entity within the model, itself being a complex type with other contained entities (aka tables).

The issue that I have is that when I try to read from the view I get the error “The entity type NetworkSuppliersByClient is not part of the model for the current context.“.

However, when I try to register the entity with the context as a DbSet I get the error “There is already an object named ‘NetworkSuppliersByClients’ in the database.” as it tries to create a table with the same name as the already existing view.

Is there any way around this, for example to inhibit EF from trying to create the table at startup, or is there a better way to read from a view?

  • 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-06-14T12:35:49+00:00Added an answer on June 14, 2026 at 12:35 pm

    To anyone else who’s interested I ended up just side-stepping the issue.

    I mapped the entity NetworkSuppliersByClient (shown above) instead directly to the response from the view response, with the exception that I gave up trying to return the Supplier entity as an embedded entity instead returning it as a primitive long.

    public class NetworkSuppliersByClient : Entity, IKeyed<long>
    {
        public long NetworkSuppliersByClientId { get; set; }
    
        public long NetworkId { get; set; }
        public String NetworkName { get; set; }
        public long OwningClientId { get; set; }
        public long ClientId { get; set; }
        public long SupplierId { get; set; }    <-- Long, rather than "Supplier"
        public bool PublicEntry { get; set; }
    
        public long GetKey ()
        {
            return NetworkSuppliersByClientId;
        }
    } 
    

    Once I had the list of Supplier IDs as longs I then performed a subsequent Entity Framework query (using the .Contains() method) to return all of the suppliers as real EF entities.

    The key is that the entity (NetworkSuppliersByClient in my case above) shouldn’t exist as a declared DbSet member within the DbContext subclass, or indeed referenced by any entities already in an existing DbSet<>. If you enforce this rule then Entity Framework won’t try to create the table at startup and it shouldn’t cause any conflicts with the already existing view.

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

Sidebar

Related Questions

Using Microsoft SQL Server Management Studio, I have created a view, which pulls in
I have created views on the SQL Server 2005 database and this view is
i, I have one Materialized view on one server which is created by DB
I have the following tables in a SQL Server 2008 db: tblItem , which
I have created SQL Server database by Visual Studio 2010 Ultimate means in Visual
I have created SQL Server 2008 Database project using visual studio 2010. after build
I have a database that I have created using SQL Server Developer 2008. I
I have created a T-SQL query in SQL Server 2008 R2 that is a
I have created a cube in Sql Server Analysis Service. I have a table
I have created one user named tuser with create database rights in SQL server

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.