locked
Entity Framework - Bind Master-Details to BindingSource.. RRS feed

  • Question

  • english:

    hi,

    i had let created my DataModel from a existing DataBase. This Database also includes the foreign keys, so the relations should be generated automaticly from the framework, right?.

    What i want to do, is to bind content from three Tables to one DataGridView!

    The three tables are:

    Projekt: ProjectNr (PK),ProjectName,CompanyNr(FK), PartnerNR(FK).

    Company: CompanyNr,CompanyName,CompanyTown....ect.

    Partner : PartnerNr,PartnerName,PartnerTel....ect

     

    I`ve worked around with bindingSources, so i shoud/can do it now, too?!

    So, i´ve created the DataModel, and my 'Project'-Table contains ProectNr,ProjectName and 2 navigation properties ( Company,Partner)

     

    And now my problem!

    How can I populate my DataGridView with a BindingSource, showing the ProjectNR,ProjectName, CompanyName and PartnerName?

    I´ve tried it with an .Include, but doesnt work to!...

    My Formload is this:

     bstest = New BindingSource
            With frmMain.contextMatrixDongle
                bstest.DataSource = .Project.Include("Company").Include("Partner")
                grdProject.DataSource = bstest
            End With

     

    I initialized the entity-context in the form frmMain...

    I use VS2008 + SP1 and .Net Framework 3.5 SP1...
    I Hope that someone could help me, and even understand me!! ;)

    ...i am a bit frustrated now! :(

     

    german:

    hi,

    ich habe mein DataModel ahnahnd einer vorhanden DB erstellt. Die DB besitzt auch Fremdschlüssel. Die Beziehungen werden im EF-DataModel doch durch diese Fremdschlüssel "automatisch" mit erstellt, oder?

    Ich möchte jedenfalls Inhalte aus drei Tabellen in einem DataGridView unterbringen...

    die Tabellen sind so aufgebaut:

    Projekt: ProjectNr (PK),ProjectName,CompanyNr(FK), PartnerNR(FK).

    Company: CompanyNr,CompanyName,CompanyTown....ect.

    Partner : PartnerNr,PartnerName,PartnerTel....ect

     

    Ich würde das ganze dann an eine BindingSource anbinden.

    Im DataModelDesigner hab ich in der Entität 'Project' die Navigationseigenschaften "Company" und "Partner"...

    ich möchte aber im DataGridView allerdings nur den Projektnamen, die Nr, und den CompanyName und PartnerName angezeigt haben.

    Wie kann das realisiert werden??

    Im Formload habe ich:

     bstest = New BindingSource
            With frmMain.contextMatrixDongle
                bstest.DataSource = .Project.Include("Company").Include("Partner")
                grdProject.DataSource = bstest
            End With

     

    Der Context wurde in frmMain initialisiert. Also greife ich über frmMain.contextMatrixDongle darauf zu.

     

    Ich benutze VS2008 + SP1 und .Net Framework 3.5 SP1...

    Kann mir jemand da weiter helfen?
    • Moved by VMazur Wednesday, July 14, 2010 10:24 AM (From:ADO.NET Managed Providers)
    Wednesday, July 14, 2010 8:29 AM

Answers

  • I think your main problem is not having the Foreign Keys available on the Project entity(CompanyId, PartnerId etc.,).

    EF1 does not expose the foreign key columns. Instead, it exposes them as navigation properties. This is a problem many times, esp for control binding. You can "fake" foreign keys in the Entity by extending the Entity class. Please look here: How to fake Foreign Key Properties in .NET 3.5 SP1.

    Once you have foreign keys enabled, rest of the binding should be same as you do with normal datasets.

    I do not have experience with WinForms, but this is the approach I used with ASP.NET.

    Wednesday, July 14, 2010 2:15 PM

All replies

  • I think your main problem is not having the Foreign Keys available on the Project entity(CompanyId, PartnerId etc.,).

    EF1 does not expose the foreign key columns. Instead, it exposes them as navigation properties. This is a problem many times, esp for control binding. You can "fake" foreign keys in the Entity by extending the Entity class. Please look here: How to fake Foreign Key Properties in .NET 3.5 SP1.

    Once you have foreign keys enabled, rest of the binding should be same as you do with normal datasets.

    I do not have experience with WinForms, but this is the approach I used with ASP.NET.

    Wednesday, July 14, 2010 2:15 PM
  • Thank you very much!

    I recognized that the FK´are navigation properties!

    For a first sight on your link, it looks like a solution for my problem!

     

    Wednesday, July 14, 2010 3:06 PM