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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T02:09:20+00:00 2026-05-27T02:09:20+00:00

I have a ListView which I filled in from SQL Server view called view_ListaKlientow

  • 0

I have a ListView which I filled in from SQL Server view called view_ListaKlientow with this query:

    private void fillClientsList() {
        using (var context = new EntityBazaCRM()) {
            var listaKlientow = from d in context.view_ListaKlientow
                                select d;
            objectListViewListaKlientow.SetObjects(listaKlientow.ToList());
            objectListViewListaKlientow.AutoResizeColumns();
        } 
    }

Then after user double clicks one row in ListView, I read ID from the view_ListaKlientow and use fillClientGui to fill necessary fields in gui (for a test only one field is included).

    private void objectListViewListaKlientow_DoubleClick(object sender, EventArgs e) {
        foreach (view_ListaKlientow user in objectListViewListaKlientow.SelectedObjects) {
            int id = user.KlienciID;
            fillClientGui(id);
            TabPageActivate(tabControlMain, tabPageKlient);
        }
    }
    private void fillClientGui(int klientId) {
        using (var context = new EntityBazaCRM()) {
            IQueryable<Klienci> klient = context.Kliencis.Include("Podmioty").Where(d => d.KlienciID == klientId);
            foreach (var source in klient.ToList()) {
                textNIP.Text = source.Podmioty.PodmiotNIP;
            }
        }
    }

Now I’m wondering since I know exactly I’m querying for one ID i should be getting only particular client and not a list of clients so foreach from fillClientGui just to travers IQueryable<Klienci> seems like additional unnecessary code. Or this is how it should be done? I’m trying to learn Entity and some things aren’t just clear to me yet 🙂

  • 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-27T02:09:21+00:00Added an answer on May 27, 2026 at 2:09 am

    If you’re sure that you’ve got only one instance to be returned form the database, you can use the extension function FirstOrDefault() in this case:

    var source = context.Kliencis.Include("Podmioty").Where(d => d.KlienciID == klientId).FirstOrDefault();
    textNIP.Text = source.Podmioty.PodmiotNIP;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a following problem. I have a ListView which returns data from SQL
I have ListView with custom Adapter which supplies View to ListView in this way:
I have a listview which is filled with data form sqlitedatabase. A list-view element
This is a very common scenario: displaying images in a ListView which have to
My project is .NET/WinForms. I have a list view which is always filled with
i have a ListView which contains objects bound from an collection. The representation of
I have a listview which populates its content from SQLite Database. Here's my code:
I have a listview called lvQuestions which has a label (called lblMissingField ) on
This is probably easy as well. But I have this listview which contains exe
I have a listview which is filled by AsyncTask and I am trying to

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.