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 6805471
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T19:35:25+00:00 2026-05-26T19:35:25+00:00

I working to code first technique with EF4.1, WCF webservice, and Sql azure. To

  • 0

I working to code first technique with EF4.1, WCF webservice, and Sql azure. To improve the performance i wanted to create the View to fetch data at server side. but according to this
we can not use sql View with EF code first.
Because the database and models are defined. it has the data. to re create and dump data for the only creating view is time taking process.

so i just created the View explicitly at sql server.
now I want to call that view from my wfc web service. Now i want to access that view as dataset in WCF. need guidlines. and right approach

  • 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-26T19:35:26+00:00Added an answer on May 26, 2026 at 7:35 pm

    Could you define a table in codefirst with the same columns, then create a custom initializer that drops the table from the database and creates it again as a view?

    Then you should be able to query it just like normal.

    Edit Update to show working example

    public class User
    {
      public int Id { get; set; }
      public string Email { get; set; }
    }
    
    public class UserView
    {
      public int Id { get; set; }
      public string Email {get; set;}       
    }
    
    public class TestContext : DbContext
    {
      static TestContext()
      { 
        Database.SetInitializer<TestContext>(new DatabaseInitializer());
      }
    
      public DbSet<User> Users { get; set; }
      public DbSet<UserView> UserView { get; set; }
    }
    
    
    class DatabaseInitializer : DropCreateDatabaseIfModelChanges<TestContext>
    {
      protected override void Seed(TestContext context)
      {
        base.InitializeDatabase(context);
        context.Database.ExecuteSqlCommand("drop table UserViews");
        context.Database.ExecuteSqlCommand(@"CREATE VIEW [dbo].[UserViews] AS SELECT * 
          from [dbo].[Users]
          GO");
        context.Users.Add(new User() { Email = "test@test.com" });
      }     
    }
    

    …

    using (TestContext context = new TestContext())
    {
      context.UserView.ToList(); //contains all the users
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The code below working for only first div. I can't display other divs when
I have a problem with ui dialog close function. My code working first click
I've successfully mapped an Entity Framework Code-First data model with an existing Sql Server
I'm working on an EF Code first site, and I've written my classes and
I get a ModelValidationException (at the bottom) when working with EF-Code First. It wants
I'm working on EF CTP5 Code First development with an existing database. I need
I'm working through the Building an MVC 3 App with Code First and Entity
I currently working on a application that use Entity Framework 4.1 (code first) and
I am working on a mvc3.0 app using EF code first and mvc scaffolding.
I am using EF4 Code First (CTP5) to generate my database and I am

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.