How do you update a table with a foreign key to another table in ADO.Net Entity Model?

前端 未结 1 344
长发绾君心
长发绾君心 2021-01-18 05:55

I have 2 tables, Table1 has a primary key \'CustomizationId\', and Table2 has a FK Customizationid which matches this. Table2 has no primary key.

I am trying to add

1条回答
  •  栀梦
    栀梦 (楼主)
    2021-01-18 06:24

    As far as the EF is concerned the table without a PK is a View.

    This means you have two options:

    1. Tell a little white lie, and convince the EF that the 'view' is a table
    2. Add modification functions (Insert/Update/Delete) so you can edit them.

    Generally modification functions are stored procedures, but you can actually add T-SQL directly to the SSDL if you don't have access to the database...

    I.e. something like this in the element of the EDMX for each action (insert, update and delete):

    
           
                    INSERT dbo.TCode(ID, Name) VALUES (@ID, @Name)
           
           
           
    
    

    Once you have the modification functions in your SSDL you need to map them so that the EF uses them as required.

    In your situation I recommend (1).

    Hope this helps.

    Cheers Alex

    0 讨论(0)
提交回复
热议问题