none
Inserting parent and child in Linq RRS feed

  • Question

  •      
      using (TestDbaseDataContext dContext = DatabaseHelper.GetDatabase(databaseString))
                {
                    if (testStation.TestStationID <= 0)
                    {
                        dContext.TestStations.InsertOnSubmit(testStation);
                    }
                    else
                    {
                        dContext.TestStations.Attach(testStation, true);
                   dContext.TestStationDetails.AttachAll(testStation.TestStationDetails.Where(a => !a.IsNew), true);
    dContext.TestStationDetails.InsertAllOnSubmit(testStation. TestStationDetails.Where(a => a.IsNew)
    
    
                    }
    
                    dContext.SubmitChanges();
                }

    What I am trying to do is insert the a new record to testStation with child object of TestStationDetails. But whenever I am typing "testStation.TestStationDetails" it is not showing in the intellisense
    There's an association in my dbml, do you know what am I missing here?

    Wednesday, September 9, 2009 9:17 PM

Answers

  • Hi Caridad,

    Thanks for your contacting MSDN forums! I will be working on the issue with you.

     

    I have a quick test in my side (Visual Studio 2008) but cannot reproduce the issue you describe. The following is screenshot about my database structure,

    /

     

    And here is the dbml file’s content,

      <Table Name="dbo.Articles" Member="Articles">

          ………

          <Association Name="Article_Feedback" Member="Feedbacks" ThisKey="ArticleID" OtherKey="FeebackID" Type="Feedback" />

          ………

      <Table Name="dbo.Feedback" Member="Feedbacks">

          ………

          <Association Name="Article_Feedback" Member="Article" ThisKey="FeebackID" OtherKey="ArticleID" Type="Article" IsForeignKey="true" />

           ………

    When I type Article. , Visual Studio 2008 always shows me the intellisense of Feedbacks.

     

    Right now, based on my research, I have the following thoughts that may address the issue here,

    1.    I find some discussions on the net that the LINQ parent-child intellisense is lost from Visual Studio because the Primary key is not set for corresponding tables. So could you please check if this is the problem in this case?

     

    2. If we are using Visual Studio 2010 beta1, we can encounter similar issues on C# projects. This is a known issue which the PG is currently working on and trying to fix in Visual Studio 2010 RTM.

    http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=458759

     

    If the above scenarios do not apply to you, we need some future information to research and give future ideas. Would you mind letting me know,

    1)    Could you get the child by intellisense in other location?

    2)    Does the project run without any error just missing the intellisense?

    3)    Which version of Visual Studio do you use?

    4)    Have you tried to create a clean application to work on this?

     

    Looking forward to your reply! Have a nice day!

     

    Best regards,

    YiChun Feng - MSFT

    • Marked as answer by maridob Thursday, September 10, 2009 1:11 PM
    Thursday, September 10, 2009 6:32 AM

All replies

  • Hi Caridad,

    Thanks for your contacting MSDN forums! I will be working on the issue with you.

     

    I have a quick test in my side (Visual Studio 2008) but cannot reproduce the issue you describe. The following is screenshot about my database structure,

    /

     

    And here is the dbml file’s content,

      <Table Name="dbo.Articles" Member="Articles">

          ………

          <Association Name="Article_Feedback" Member="Feedbacks" ThisKey="ArticleID" OtherKey="FeebackID" Type="Feedback" />

          ………

      <Table Name="dbo.Feedback" Member="Feedbacks">

          ………

          <Association Name="Article_Feedback" Member="Article" ThisKey="FeebackID" OtherKey="ArticleID" Type="Article" IsForeignKey="true" />

           ………

    When I type Article. , Visual Studio 2008 always shows me the intellisense of Feedbacks.

     

    Right now, based on my research, I have the following thoughts that may address the issue here,

    1.    I find some discussions on the net that the LINQ parent-child intellisense is lost from Visual Studio because the Primary key is not set for corresponding tables. So could you please check if this is the problem in this case?

     

    2. If we are using Visual Studio 2010 beta1, we can encounter similar issues on C# projects. This is a known issue which the PG is currently working on and trying to fix in Visual Studio 2010 RTM.

    http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=458759

     

    If the above scenarios do not apply to you, we need some future information to research and give future ideas. Would you mind letting me know,

    1)    Could you get the child by intellisense in other location?

    2)    Does the project run without any error just missing the intellisense?

    3)    Which version of Visual Studio do you use?

    4)    Have you tried to create a clean application to work on this?

     

    Looking forward to your reply! Have a nice day!

     

    Best regards,

    YiChun Feng - MSFT

    • Marked as answer by maridob Thursday, September 10, 2009 1:11 PM
    Thursday, September 10, 2009 6:32 AM

  • I am using Visual Studio 2008 and the error that I am getting is "TestStation does not contain a definition for 'TestStationDetail' and no extension method 'TestStationDetail' accepting first argument of type TestStation could be found."

    And yes - my TestStation has primary key although originally my TestStationDetails doesn't have primary key but it does have fk from TestStation. When I added a primary key in the TestStationDetails VS starts recognizing the association between the two.


    Thanks!

    Thursday, September 10, 2009 1:07 PM