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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T13:43:03+00:00 2026-05-25T13:43:03+00:00

I have a few tables I’m dealing with regarding a Goals application (screen grab

  • 0

I have a few tables I’m dealing with regarding a “Goals” application (screen grab is below). I’m using MVC 3, razor and linq.

I am using a model, goalsModel, to retrieve my data:

public goals GetGoal(int id)
{
return qDB.goals.Single(g => g.goalID == id);
}

I’d like Activities to be available as well… where I could do something like:

public goals GetGoalActivities(int id)
{
return qDB.ilpActivities.Where(g => g.goalID == id);
}

However this returns an error. The smart tags for don’t show any columns available for ilpActivities. I’ve seen several methods of writing code in the controller where it’s a linq query – but I’d really like to use the format above if possible for consistency.

Here’s a link that I’ve been trying to follow that may do what I want. Keep in mind, however, I’ll eventually be editing existing activities, creating new ones, and deleting activities. The link: http://geekswithblogs.net/michelotti/archive/2007/12/30/118076.aspx

[Edit]
I couldn’t post an image as a new user. My tables consist of goalID as the primary key of goals and foreign key in ilpActivities. ilpActivities has a primary key of activityID.

[Update]

My tables look something like this (simplified to include relevant fields):
goals: goalID, goalName, goalDescr
ilpActivities: activityID, goalID, activityName

I have a dbml file: employeeDataClasses.dbml that was generated for me after dragging the tables in on design mode. It recognized ilpActivities as a child of goals

I have a goalsModel.cs file:

namespace ILP.Models
{
public class goalsModel
{
    #region services
    public interface IGoalsService
    {
        List<goals> GetAllGoals(string oprID);
        bool CreateGoal(goals poll);
        List<ilpGoalStatus> GetStatuses();
        goals GetGoal(int id);
        bool EditGoal(goals poll);
        List<ilpActivity> GetGoalActivities(goals goal);
    }

    public class AssetService : IGoalsService
    {
        private goalsDataClassesDataContext qDB;

        public AssetService()
        {
            qDB = new goalsDataClassesDataContext();
        }

        #region IGoalsService Members
            public List<ilpActivity> GetGoalActivities (goals goal) 
        {
            IEnumerable<ilpActivity> activities = from g in qDB.goals
                         join a in qDB.ilpActivities on g.goalID equals a.goalID
                         where a.goalID == goal.goalID
                         select a;

            return activities.ToList();
        } 

In my controller:

namespace ILP.Controllers
{
public class HomeController : Controller
{

    private goalsModel.IGoalsService qService;

    public HomeController()
    {
        qService = new goalsModel.AssetService();
    }
        [Authorize]
    public ActionResult _CreateActivity(int goalID)
    {
        //var status = qService.GetStatuses();
        ViewBag.Status = new SelectList(qService.GetStatuses().ToList(), "goalStatusID", "goalStatus");
// not sure what to do here to get activity model in....
        return PartialView();
    }

In my create activity partialview I’m only getting access to the goals model:

@model ILP.Models.goals

<script src="@Url.Content("~/Scripts/jquery-1.5.1.min.js")"     type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>

@using (Html.BeginForm()) {
@Html.ValidationSummary(true)
<fieldset>
    <legend>Create an Activity</legend>

    <div class="editor-label">
        @Html.LabelFor(model => model.goalName)
    </div>
    <div class="editor-field">
        @Html.EditorFor(model => model.goalName)
        @Html.ValidationMessageFor(model => model.goalName)
    </div>
.... etc....

In my view I need to access activityName of ilpActivities – but the only options are coming from goals table.

  • 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-25T13:43:03+00:00Added an answer on May 25, 2026 at 1:43 pm

    Can you change:

    public goals GetGoalActivities(int id) { return qDB.ilpActivities.Where(g => g.goalID == id); }
    

    to:

    public IEnumerable<ilpActivities> GetGoalActivities(int id) { return qDB.ilpActivities.Where(g => g.goalID == id); }
    

    because qDB.ilpActivities.Where(g => g.goalID == id); returns an IEnumerable of activites, not a single goal like the previous method.

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

Sidebar

Related Questions

I have a few tables that I've defined like the below examples: class TableA
in my application I have a few CListCtrl tables. I fill/refresh them with data
I'm using MS ACCESS 2000. I have few tables in AB.mdb linked to some
I am using C#, EF and SQL Server and have few tables with parent-child
I have few DB tables, witch are build using inheritance from one table witch
I have a few tables that have similar fields but not exactly the same.
We have a few tables with persisted computed columns in SQL Server. Is there
I have a few tables with 70-80 columns in them. I would like to
I have a few huge tables on a production SQL 2005 DB that need
I have a MS Access database with few tables and a form. When more

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.