locked
Drop Member Variable from Generated Class RRS feed

  • Question

  • Hi, 

    I am looking to remove a navigation member variable from one of my generated classes that were generated from Entity Framework Core. Right now, if I remove a navigation variable, I get a SQL exception error when I call a LINQ method. Is there an easy way for me to remove one of these navigation variables?

    Thanks

    Monday, August 14, 2017 4:20 PM

All replies

  • Hi Sam_Mallabone,

    Thank you for posting the problem here.

    According to your description, you would like to deleted a navigation property from some classes which are generated from existing database.

    For some navigation variables in your generated classes, they map your foreign keys and represent the relationship of your generated classes.

    According to your previous thread, you would like to remove User and Contract navigation variables from generated SerialNumbers class. If the User Table and Contract Table are not used in your code, you could execute the following command to generate classes on Package manage console.

    Scaffold-DbContext "Server=VDI-V-JIANPW\SQLEXPRESS;Database=FirstDatabase;Trusted_Connection=True;" Microsoft.EntityFrameworkCore.SqlServer -t ("SerialNumbers "," Features")

    The User and Contract navigation variables will not be generated in your SerialNumbers class.

    If you want to generate User and Contract classes, I made a test which I directly deleted a navigation property ( not update database.)from a generated class and executed select and insert operations. It worked well.

    >> I get a SQL exception error when I call a LINQ method.
    Could you please indicate the exception?

    If you could provide a demo which reproduces your problem, I will help you better and faster.

    I’m glad to be of help to you.

    Best Regards,

    Cole


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, August 15, 2017 7:05 AM