How can I prevent foreign keys from being loaded into my DataGrid?


Kara J

Right now, I'm getting all the information under the table and binding it to my DataGrids.

However, this makes my foreign keys visible on the DataGrid, which I don't want. Also, I don't see an ID column.

How can I select only certain columns from the database and bind them to the DataGrid instead of binding all the data to the DataGrid?

I think I just need to write a query, but it doesn't seem to work. Maybe because I'm still new to Entity Framework.

This is how I store the data into the db...:

 using (var db = new DMIDataContext())
{LotInformation newLot = new LotInformation();

        newLot.Id = lot.Id;
        newLot.lot_number = lot.lot_number;
        newLot.exp_date = lot.exp_date;

  foreach (Components comp in lot.Components)
        {

                   newLot.Components.Add(comp);

         }
         ComponentsList = newLot.Components;

  foreach (Families fam in lot.Families)
        {

                   newLot.Families.Add(fam);

         }
         Families = newLot.Families; 

         db.LotInformation.Add(newLot);
         db.SaveChanges();

This is how I get the database data:

 public static void ReadLot(string lotNumber)
    {

        using (var db = new DMIDataContext())
        {
            try
            {
                LotInformation lotInfo = db.LotInformation.FirstOrDefault(r => r.lot_number.Equals(lotNumber));
            }
            catch (InvalidOperationException e)
            {

            }
        }
    }

I think the problem is in the above query...I tried using FirstOrDefault(). Select(), but I guess I can't perform a select select after FirstOrDefault...don't know why.

The way the foreign key is set up in my class is:

    public virtual int LotInformationId { get;  set; }
    public virtual LotInformation LotInformation { get; set; }

But I don't want data bound to my dataGrid...

Hope this is clear. If you have any questions, please ask me.

Thanks!

Man

Like Michael Perrenoud said, you can specify the desired columns in the xaml:

  <DataGrid ItemSource="{Binding YourCollection}" SelectedItem="{Binding YourCurrentSelectedItem}">
      <DataGrid.Columns>
         <DataGridTextColumn Header="SomeColumnHeader" Binding={Binding SomePropertyOnTheModel} />
      </DataGrid.Columns>
  </DataGrid>

Related


How can I prevent my Javascript files from being cached?

Bdfy: I have a simple html: <html> <body> <head> <meta charset="utf-8"> <meta http-equiv='cache-control' content='no-cache'> <meta http-equiv='expires' content='0'> <meta http-equiv='pragma' content='no-cache'> <script src="test.js"></script> </body> </html>

How can I prevent my Javascript files from being cached?

Bdfy: I have a simple html: <html> <body> <head> <meta charset="utf-8"> <meta http-equiv='cache-control' content='no-cache'> <meta http-equiv='expires' content='0'> <meta http-equiv='pragma' content='no-cache'> <script src="test.js"></script> </body> </html>

How can I prevent my mail from being used in PHP?

Louis 'LYRO' DuPont I have a custom email address for my web domain, the problem is that I found out that anyone can use my personal address to impersonate me and use mail. Is there any way to stop anyone from using my email address with such scripts? Amadan T

How can I prevent my mail from being used in PHP?

Louis 'LYRO' DuPont I have a custom email address for my web domain, the problem is that I found out that anyone can use my personal address to impersonate me and use mail. Is there any way to stop anyone from using my email address with such scripts? Amadan T

How can I prevent my terminal from being damaged?

Aksha Sharma I am using the command (in a shell script) watchin my docker image . Order: watch -d -t -g ls -la ${DIR_TO_WATCH} && sleep 5 && ${COMMAND} | tee This command is watching the directory and if there is any change in the directory structure we wil

How can I prevent my launcher from being killed by the OS?

RoFF I'm working on a project for a third party Android launcher. I found it was often killed by the OS when it was running in the background, even if it was the default launcher. The OS will kill many applications when the available memory is low, I asked me

How can I prevent my output from being Nan?

Chris Code I'm trying to make a budgeting app that will remind the user of the remainder after subtracting income from expenses, my reminder keeps saying Nan. I am using a for loop to sum up the income and expenses entered by the user. I have included my code.

How can I prevent my Javascript files from being cached?

Bdfy: I have a simple html: <html> <body> <head> <meta charset="utf-8"> <meta http-equiv='cache-control' content='no-cache'> <meta http-equiv='expires' content='0'> <meta http-equiv='pragma' content='no-cache'> <script src="test.js"></script> </body> </html>

How can I prevent my launcher from being killed by the OS?

RoFF I'm working on a project for a third party Android launcher. I found it was often killed by the OS when it was running in the background, even if it was the default launcher. The OS will kill many applications when the available memory is low, I asked me

Can I prevent OpenPGP keys from being synced to the keyserver?

userDepth I want to generate an OpenPGP key and use it with Thunderbird, but when I do this in Seahorse I don't want the key to be synced with the key server. Jens was No, there is no way to prevent the upload of keys to the key server. RFC 4880 (OpenPGP) neit

How to prevent Item from being added to DataGrid?

WoIIe my question I'm trying to prevent users from adding blank rows when using the built-in .NET AddNewItem functionality . So when the user tries to commit the AddNew transaction and leave it empty, it should disappear from it .DataGridDataGridDataGridPageIt

How to prevent Item from being added to DataGrid?

WoIIe my question I'm trying to prevent users from adding blank rows when using the built-in .NET AddNewItem functionality . So when the user tries to commit the AddNew transaction and leave it empty, it should disappear from it .DataGridDataGridDataGridPageIt

How to prevent Item from being added to DataGrid?

WoIIe my question I'm trying to prevent users from adding blank rows when using the built-in .NET AddNewItem functionality . So when the user tries to commit the AddNew transaction and leave it empty, it should disappear from it .DataGridDataGridDataGridPageIt

How to prevent RSpec helpers from being loaded

Coding Rabbit Currently, I'm using Capybara to write integration tests for our Rails 4 application. To make it as lightweight as possible, I wrote a capybara_helper.rbfile inside the specfolder I want to use with RSpec . However, this file is loaded every time

How to prevent RSpec helpers from being loaded

Coding Rabbit Currently, I'm using Capybara to write integration tests for our Rails 4 application. To make it as lightweight as possible, I wrote a capybara_helper.rbfile that lives in the specfolder I want to use with RSpec . However, this file is loaded eve

How to prevent RSpec helpers from being loaded

Coding Rabbit Currently, I'm using Capybara to write integration tests for our Rails 4 application. To make it as lightweight as possible, I wrote a capybara_helper.rbfile that lives in the specfolder I want to use with RSpec . However, this file is loaded eve

How to prevent RSpec helpers from being loaded

Coding Rabbit Currently, I'm using Capybara to write integration tests for our Rails 4 application. To make it as lightweight as possible, I wrote a capybara_helper.rbfile that is inside the folder I want to specuse with RSpec . However, this file is loaded ev

How to prevent RSpec helpers from being loaded

Coding Rabbit Currently, I'm using Capybara to write integration tests for our Rails 4 application. To make it as lightweight as possible, I wrote a capybara_helper.rbfile that is inside the folder I want to specuse with RSpec . However, this file is loaded ev

How to prevent RSpec helpers from being loaded

Coding Rabbit Currently, I'm using Capybara to write integration tests for our Rails 4 application. To make it as lightweight as possible, I wrote a capybara_helper.rbfile that is inside the folder I want to specuse with RSpec . However, this file is loaded ev