locked
OnFieldChanging for ForeignKey field RRS feed

  • Question

  • User-1425666379 posted

    In the partial class for my Products entity, I can capture change events for validation using

    partial void OnMyFieldChanging(bool value)
    {
    }

     But I don't see any Foreign Key fields showing up for those OnXXXXChanging events. If I want to capture changes of foreign key values, how would I do that?

    Jeff

    Monday, September 15, 2008 3:33 PM

Answers

  • User1641955678 posted

    Steve's reply applies to Linq To Sql, but I'm guessing you're using Entity Framework.  In EF, the FK columns are not part of the entity at all, which is why you don't see those partial methods.  Note that this is true of EF in general, and not anything specific to Dynamic Data.  You may want to post to the Entity Framework forum to make sure you hit most of the EF experts.

    David

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, September 15, 2008 6:28 PM

All replies

  • User-330204900 posted

    Hi you should see them here is the extesibility methods for the Order table in Northwind: 

    #region Extensibility Method Definitions
    partial void OnLoaded();
    partial void OnValidate(System.Data.Linq.ChangeAction action);
    partial void OnCreated();
    partial void OnOrderIDChanging(int value);
    partial void OnOrderIDChanged();
    partial void OnCustomerIDChanging(string value);
    partial void OnCustomerIDChanged();
    partial void OnEmployeeIDChanging(System.Nullable<int> value);
    partial void OnEmployeeIDChanged();
    partial void OnOrderDateChanging(System.Nullable<SYSTEM.DATETIME> value);
    partial void OnOrderDateChanged();
    partial void OnRequiredDateChanging(System.Nullable<SYSTEM.DATETIME> value);
    partial void OnRequiredDateChanged();
    partial void OnShippedDateChanging(System.Nullable<SYSTEM.DATETIME> value);
    partial void OnShippedDateChanged();
    partial void OnShipViaChanging(System.Nullable<int> value);
    partial void OnShipViaChanged();
    partial void OnFreightChanging(System.Nullable<decimal> value);
    partial void OnFreightChanged();
    partial void OnShipNameChanging(string value);
    partial void OnShipNameChanged();
    partial void OnShipAddressChanging(string value);
    partial void OnShipAddressChanged();
    partial void OnShipCityChanging(string value);
    partial void OnShipCityChanged();
    partial void OnShipRegionChanging(string value);
    partial void OnShipRegionChanged();
    partial void OnShipPostalCodeChanging(string value);
    partial void OnShipPostalCodeChanged();
    partial void OnShipCountryChanging(string value);
    partial void OnShipCountryChanged();
    #endregion

     See the BOLD ITALIC lines these the FK columns

    Hope this helps [:D]

    Monday, September 15, 2008 5:40 PM
  • User1641955678 posted

    Steve's reply applies to Linq To Sql, but I'm guessing you're using Entity Framework.  In EF, the FK columns are not part of the entity at all, which is why you don't see those partial methods.  Note that this is true of EF in general, and not anything specific to Dynamic Data.  You may want to post to the Entity Framework forum to make sure you hit most of the EF experts.

    David

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, September 15, 2008 6:28 PM
  • User-1425666379 posted

    Yes, it's EF. Thanks, both of you! I'll take it to the EF folks.

    For anyone interested, question is posted here
    http://forums.microsoft.com/msdn/ShowPost.aspx?PostID=3880631&SiteID=1

     

    Monday, September 15, 2008 7:30 PM