none
Unexpected "Invalid column name" Exception RRS feed

  • Question

  • I keep getting  "Invalid Column name 'Order_OrderId1'", "Invalid Column name 'Product_ProductID1'" exceptions about two weeks ago. I did not modify my code at all, and neither did I modify my database. The only thing I changed was my .edmx: I deleted and recreated it.

    My EntityFramework's version is 6.0.0.0.

    Here is the T-SQL Table definition of the table involved (OrderLines):

    CREATE TABLE [dbo].[OrderLines] (
        [OrderLineId]       INT IDENTITY (1, 1) NOT NULL,
        [Quantity]          INT NOT NULL,
        [Product_ProductID] INT NULL,
        [Order_OrderId]     INT NULL,
        CONSTRAINT [PK_dbo.OrderLines] PRIMARY KEY CLUSTERED ([OrderLineId] ASC),
        CONSTRAINT [FK_dbo.OrderLines_dbo.Products_Product_ProductID] FOREIGN KEY ([Product_ProductID]) REFERENCES [dbo].[Products] ([ProductID]),
        CONSTRAINT [FK_dbo.OrderLines_dbo.Orders_Order_OrderId] FOREIGN KEY ([Order_OrderId]) REFERENCES [dbo].[Orders] ([OrderId])
    );

    Here is the corresponding class created automatically by the EntityFramework (when .edmx is created):

        

        public partial class OrderLine
        {
            public int OrderLineId { get; set; }
            public int Quantity { get; set; }
            public Nullable<int> Product_ProductID { get; set; }
            public Nullable<int> Order_OrderId { get; set; }

            public virtual Order Order { get; set; }
            public virtual Product Product { get; set; }
        }

    The cardinality (inferred automatically by the EntityFramework from the T-SQL table definition) between OrderLines table and Orders table (or Products table) is n to 0..1. 

    The exceptions go away only if I manually change the above OrderLine class definition into:

        public partial class OrderLine
        {
            public int OrderLineId { get; set; }
            public int Quantity { get; set; }

            public Order Order { get; set; }
            public Product Product { get; set; }
        }

    I don't understand why. Order_OrderId1, Product_ProductID1 are not even defined (only Order_OrderId, Product_ProductID, are defined), but the exceptions are complaining about them.

    Has any thing changed since two weeks ago, as it did not happen two weeks ago (again, it happened after I re-created my .edmx two weeks ago) ?

    Thanks in advance for your help.


    Goldstar Lee

    Monday, July 4, 2016 2:36 AM

Answers

  • Hi,

    Can you rename the foreign key column names in your order line table. Product_ProductID to ProductID and Order_OrderId to OrderId then remove the OrderLine entity from the model then add it once again.

    Please let me know if you still see errors. Also you should see two columns added with the name Product_ProductId and Order_OrderId


    Thanks, Mahmoud

    • Marked as answer by Goldstar Lee Monday, July 4, 2016 11:36 PM
    Monday, July 4, 2016 8:41 PM

All replies

  • Hi Goldstar Lee,

    According to your code snippet, it seems ok, please search on your solution with keyword named 'Order_OrderId1' and check if it has a property named 'Order_OrderId1'.

    In addition, If the issue still is exist. Could you please provide a simple demo with the issue via OneDrive. I'll reproduce your issue on my side and try to find a solution to resolve it.

    Best regards,

    Cole Wu


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, July 4, 2016 9:27 AM
    Moderator
  • Hi,

    You many need to check your entity model. can you open it and navigate to OrderLine entity, if you find properties like Order_OrderId1 or Product_ProductId1

    as in the below image, UnitCost1 is invalid property and validation gives an error

    remove these two properties from the entity and click Validate, if validation is complete without errors so your issue will be resolved.


    Thanks, Mahmoud

    Monday, July 4, 2016 11:38 AM
  • Hi Cole Wu,

    I don't have 'Order_OrderId1' references in my entire solution, not at all.

    I never set up a demo with OneDrive. How to do it ? Is it by setting up a Console Application ? If yes, my solution is a .NET Web Application, which includes EntityFramework, DataBase, etc, can a Console Application involve EntityFramework, DataBase also ? The problem only occurs if EntityFramework is involved.

    Could you give me pointers on the above.

    My true appreciation in advance,


    Goldstar Lee

    Monday, July 4, 2016 7:48 PM
  • Hi Mahmoud,

    I don't have those properties at all, as you can see below. Thanks so much.

    


    Goldstar Lee

    Monday, July 4, 2016 8:02 PM
  • Hi,

    Can you rename the foreign key column names in your order line table. Product_ProductID to ProductID and Order_OrderId to OrderId then remove the OrderLine entity from the model then add it once again.

    Please let me know if you still see errors. Also you should see two columns added with the name Product_ProductId and Order_OrderId


    Thanks, Mahmoud

    • Marked as answer by Goldstar Lee Monday, July 4, 2016 11:36 PM
    Monday, July 4, 2016 8:41 PM
  • Mahmoud,

    It works, very cleanly. Great ! Thanks so much.

    P.S. Still mysterious to me, there were NO problems until two weeks ago with using Product_ProductID, then suddenly it failed. 


    Goldstar Lee

    Monday, July 4, 2016 11:36 PM
  • Hi Cole Wu,

    Mahmoud has found the solution (see my reply to him), so I don't need to set up a demo on OneDrive anymore.

    About my question regarding OneDrive, I guess I have my own answer (correct me if I am wrong): just use it as a storage, copy my whole application to it, and invoke it using whatever mechanism it is meant for. In my case, after copying to OneDrive, invoke the application with Visual Studio.

    Thanks again.


    Goldstar Lee

    Monday, July 4, 2016 11:48 PM
  • We're glad that your issue is resolved. 

    It might be a change has been done on the database side in the two weeks caused this issue and it is shown when you updated the entity model.


    Thanks, Mahmoud

    Tuesday, July 5, 2016 2:38 PM