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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T12:12:10+00:00 2026-05-30T12:12:10+00:00

I am using LINQ to SQL in my project. I have two tables Category

  • 0

I am using LINQ to SQL in my project.
I have two tables Category and Artifacts with a one-to-many relationship between Category and Artifacts. On the basis of CatgID I am trying to delete artifacts. The query that I have written checks whether any artifact exist with a foreign key of id, then I am grouping Artifact ID to g so as to count so that I can make a condition to pass the Artifact ID as parameter to a function which will delete everything in the Artifacts table.

I am not able to select ArtId using the same range variable ‘a’. Why not? How can I do this or otherwise achieve what I want?

public static void DeleteCategory(int id)
{
    var result = from a in adb.Artifacts
                     where a.CatgId == id
                     group a by a.ArtId into g
                     select new { count = g.Count(), **artid = a.ArtId** }; //not able to get ArtId using range variable a.

    if (result.count > 0)
    {
        foreach (var r in result)
        {
            MyArtifact.DeleteByKey(r.artid);
        }
    }
}
  • 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-30T12:12:12+00:00Added an answer on May 30, 2026 at 12:12 pm

    You can just use g.ArtId because you group by ArtId:

    public static void DeleteCategory(int id)
    {
        var result = from a in adb.Artifacts
                     where a.CatgId == id
                     group a by a.ArtId into g
                     select new { count = g.Count(), artid = g.Key }; //not able to get ArtId using range variable a.
    
        if (result.count > 0)
        {
            foreach (var r in result)
            {
                MyArtifact.DeleteByKey(r.artid);
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using Linq-To-SQL for a project with around 75 tables. We have to keep
I have started using Linq to SQL for a project im working on and
I have a short question. Im my current project I'm using LINQ-to-SQl. That is
I have create a LINQ-to-SQL project in Visual Studio 2010 using Dynamic Data. In
We have a project using LINQ to SQL, for which I need to rewrite
I have just started a new project using a Linq to Sql model and
In one of our project we're using Linq-to-SQL to get data from our database.
I have a website project, and using Linq to SQL in it. Currently, I
I am using Linq to SQL in a two tier project where the server
i have a mvc web project and i'm using linq to sql i'm using

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.