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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T04:15:35+00:00 2026-06-09T04:15:35+00:00

I have got problem with LINQ query. In table towar I would like to

  • 0

I have got problem with LINQ query. In table towar I would like to get Kategorie.Nazwa

Example in sql: SELECT Kategorie.Nazwa FROM Towar INNER JOIN Kategorie ON Towar.Id_kat = Kategorie.Id_kat

enter image description here

Here is my problem .Where(p => category == null || p.Id_kat == category) I need name of category but I have got number. I need this p.Id_kat = SELECT Kategorie.Nazwa FROM Towar INNER JOIN Kategorie ON Towar.Id_kat = Kategorie.Id_kat I using EntityFramework DbContext.

SomeView viewModel = new SomeView
                {
                    Towar = repository.Towar
                    .Where(p => category == null || p.Id_kat == category)
                    .OrderBy(p => p.Id_tow)
                    .Skip((page - 1) * PageSize)
                    .Take(PageSize),

                    Kategorie = re.Kategorie
                    .OrderBy(p => p.Id_kat),

                    PagingInfo = new PagingInfo
                                        {
                                       CurrentPage = page,
                                       ItemsPerPage = PageSize,
                                       TotalItems = repository.Towar.Count()

                                        },
                    CurrentCategory = category

                                   };
                return View(viewModel);
            }
  • 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-09T04:15:38+00:00Added an answer on June 9, 2026 at 4:15 am

    If you setup a foreign key between Towar and Kategories, then you won’t have to do a join. You can use the POCO classes reference to the Kategory class and the power of Entity Framework. Here is an example of what I mean with a test:

    Notice how the Towar class has a property to the Kategory class.

    [ Subject( "Inner join example using entity framework") ]
    public class When_getting_towar_by_kategory_and_there_are_2_kategories
    {
        Establish context = () =>
                            {
                                myContext = new MyContext();
                                Database.SetInitializer(new CreateDatabaseIfNotExists<MyContext>());
                                var first = new Kategory { Nazwa = "First" };
                                myContext.Kategories.Add(first);
                                var second = new Kategory { Nazwa = "Second" };
                                myContext.Kategories.Add(second);
                                myContext.Towars.Add(new Towar { Cena = "found", Kategory = first });
                                myContext.Towars.Add(new Towar { Cena = "notFound", Kategory = second });
                                myContext.SaveChanges();
                                SUT = new Controller(myContext);
                            };
    
    
        private Because of = () => { result = SUT.GetTowarByKategory("First"); };
    
        private It should_return_list_filtered_by_kategory = () => { result.Select(x => x.Cena).SequenceEqual(new[] { "found" }).Should().BeTrue(); };
        private static Controller SUT;
        private static IEnumerable<Towar> result;
        private static MyContext myContext;
    }
    
    
    public class Controller
    {
        private readonly MyContext context;
    
        public Controller(MyContext context)
        {
            this.context = context;
        }
        public IEnumerable<Towar> GetTowarByKategory(string category)
        {
            var res = from t in context.Towars
                        where t.Kategory.Nazwa == category
                        select t;
    
            return res;
        }
    }
    
    public class Kategory
    {
        [Key] 
        public int Id_kat { get; set; }
        public string Nazwa { get; set; }
    }
    
    public class Towar
    {
        [Key]
        public int Id_tow { get; set; }
        public Kategory Kategory { get; set; }
        public string Cena { get; set; }
    }
    
    public class MyContext : DbContext
    {
        public DbSet<Kategory> Kategories { get; set; }
        public DbSet<Towar> Towars { get; set; }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have got very big problem because I would like to get more information
I have a many-to-many query problem in Linq-to-SQL. I have a table named user
I have got a problem to get back a parameter from my view to
The problem is: I have got a table of columns (A, B, C) where
I'm getting crazy with this problem: I have got some Oracle SQL-Reports to redesign
Im new to linQ and I've got a problem Question: if i have a
I have the following linq to sql query: DateTime linqdate = (from de in
I have a SQl query working fine, I need to convert it to LINQ
I have started using Linq to SQL in a (bit DDD like) system which
I've got a strange problem regarding linq-to-sql, and i've really tried search around for

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.