none
Extra column in datagridview RRS feed

  • Question

  • Hi,

    This problem is driving me crazy -- please help.

    I have 2 tables in a database. Table 2 has a foreign key that is the ID - primary key - in table 1. The database diagram shows a 1 to many relationship from table 1 to table 2.

    I used Linq To Sql classes and have a dbml file which contains an EntitySet in table 1 referring to table 2. The dbml file also has an EntityRef in table 2 referring to table 1. So far so good - I think.

    The problem is the following code produces an extra column that is NOT in table 2:

    var siteQuary = from x in sites

    orderby x.Site_URL ascending 

    select x;

    bindingSourceSite.DataSource = siteQuery;

    DgvSite.DataSource = bindingSourceSite;

    The extra column heading "Topic_tab"  appears to be coming from:

    private EntityRef<Topic_tab> _Topic_tab;

    Just FYI -- similar code used to display table 1 data works just fine -- no extra column. This app is being created using VS 2010 Express.

    TIA,   Joe

     

    Wednesday, October 20, 2010 7:01 PM

Answers

  • I did a simple experiment and removed the foreign key constarint between the 2 tables and regenerated the dbml -- extra dgv column is GONE.

    So how do I use linq to sql when my database has referential integrity constraints???

     

    TIA - Joe

    • Proposed as answer by Yasar M Thursday, October 21, 2010 2:29 PM
    • Marked as answer by liurong luo Thursday, October 28, 2010 5:50 AM
    Thursday, October 21, 2010 2:22 PM
  • instead of seclecting all the columns by "select X;"   why dont u select only the required columns 
    - Mohamed Yasar M

    - Mohamed Yasar M
    • Marked as answer by liurong luo Thursday, October 28, 2010 5:50 AM
    Thursday, October 21, 2010 2:34 PM

All replies

  • I did a simple experiment and removed the foreign key constarint between the 2 tables and regenerated the dbml -- extra dgv column is GONE.

    So how do I use linq to sql when my database has referential integrity constraints???

     

    TIA - Joe

    • Proposed as answer by Yasar M Thursday, October 21, 2010 2:29 PM
    • Marked as answer by liurong luo Thursday, October 28, 2010 5:50 AM
    Thursday, October 21, 2010 2:22 PM
  • instead of seclecting all the columns by "select X;"   why dont u select only the required columns 
    - Mohamed Yasar M

    - Mohamed Yasar M
    • Marked as answer by liurong luo Thursday, October 28, 2010 5:50 AM
    Thursday, October 21, 2010 2:34 PM
  • Yes, I could select only the real columns. I could also make the extra column invisible in the dgv plus I can think of other workarounds albeit requiring more code.

    However, the purpose of this thread is to hopefully get the attention of Microsoft or someone who has access to MS so that the real problem gets fixed. In the example given, the dgv should accurately display the real columns in the database table - nothing more or nothing less - unless linq to sql is documented NOT to be used when there are referential integrity constraints on a database table.

    If I am doing something wrong in the code, I welcome comments.

    TIA - Joe

    Friday, October 22, 2010 12:28 AM