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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T23:07:12+00:00 2026-05-20T23:07:12+00:00

Update I now have it working to an extent that the view is populated

  • 0

Update

I now have it working to an extent that the view is populated but my query is wrong so no data is retrieved.

My ViewModel

public class ViewProductions
{

    public string Venuename { get; set; }
    public string Showname { get; set; }
    public DateTime ProductionYear { get; set; }
    public DateTime StartDate { get; set; }
    public DateTime EndDate { get; set; }


}  

Query

var query =  
                     from f in _db.Production
                     join g in _db.Run on f.show equals g.venue
                     select new ViewProductions {
                            Venuename = g.venue,
                            Showname = f.show,

                            StartDate = g.startDate,
                            EndDate = g.endDate


                     };

        return View(query);

I have the query in SQL format

    SELECT Production.show, Run.venue, Run.startDate, Run.endDate,  Production.director, Production.designer
FROM  Production INNER JOIN
 Run ON Production.show = Run.show

Could anyone help me convert that to linq?

Thanks again

  • 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-20T23:07:13+00:00Added an answer on May 20, 2026 at 11:07 pm

    That is a good start. Remembering the idea is that the ViewModel will contain all the data needed by the view. Make it as big or as little as it needs to be.

    if you will be displaying a list of Show, you might need to change it to something like:

     public List<Show> {get; private set;}
    

    if in a given object you only use one property. Don’t worry about creating a ViewData property instead of using the entire object. So an example:

    public class Venue
    {
        public string Name;
        public string State;
        public string City;
        public int Capacity;
        ...
    }
    

    Let’s say for this given ViewModel you only need the Venue’s name. No need to add the entire Venue to it, simply add a VenuName property.

    A blog with a nice explanation.

    EDIT

    Here are some nice examples using System.Data.Linq.SqlClient.SqlMethods specifically, DATEDIFF. you could do something like this:

     where SqlMethods.DateDiffMonth(Book.EntryDate, DateTime.Now) <= 3 order by dates.startDate
    

    EDIT 2

    Try something like this:

    Couple of pointers, notice the ViewModelProduction(), you have to put the () to indicate you are creating new objects. the ToList() is to convert the IEnumerable that LINQ returns. Also in this case, I’m using the orderby on the startDate. Check out some LINQ examples. And this very useful tool: LinqPad.

    var query = (from p in db.Production
                join r in _db.Run on p.show equals r.show
                orderby r.startDate
                select new ViewModelProduction()
                {
                    show = p.show,
                    venue = r.venue,
                    startDate = r.startDate,
                    endDate = r.endDate,
                    director = p.director,
                    designer = p.director
                }).ToList();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Update: Microsoft have now reproduced the bug and are working on a fix. Whilst
UPDATE I have updated my code in response to @MichaelRushton comments. I am now
Currently, I am using an with ajax to update my mysql. Now, I have
So far i have the following code, but it doesn't seem to be working,
I have code that works in a .NET 3.5 app that isn't working when
I'm using Ruby on Rails 3 deployed at heroku. Now I have working fine
I'm relatively new to Ruby on Rails. As of now have this working code
Greetings, Until now I have mostly been working with google maps v2. I am
My project has properties for the svn:externals but to get it working I have
I have an application I have been working on and up until now 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.