LINQ to SQL: how to insert a record into a view?

I use Linq for SQL for database operations and try to perform insert operations in VIEW, it throws an error,

XXt threw exception:  System.InvalidOperationException: Can't perform Create, 
Update or Delete operations on 'Table(XXX)' because it has no primary key.

How to use LINQ to insert record in View using C #?

Thanks.

+3
source share
6 answers

You cannot insert in VIEW. You can only insert a table.

You can do this - see below.

0
source

You can insert / update views according to updated views here . Only one base table can be inserted / updated or it will fail. To implement this feature using LINQ, follow these steps:

  • .DBML ( )
  • , , /, . ;
    • / ;
      • SUM (BaseTable.ColumnName) ColumnName
      • ISNULL (BaseTable.ColumName, 0) ColumnName
      • BaseTable.ColumnName1 + '' + BaseTable.ColumnName2
    • ;
      • BaseTable.ColumnName
      • BaseTable.ColumnName MyNewName
  • , .DBML.

. , // .

+5

. , .

, ;

view..in linq sql. ( linq ).

. , . .

+4

, VIEW LINQ to SQL. , , : .

primarykey .

.dbml , , F4 ( ).

true .

. .

+2

'OnInsert' dbml.

0

, , , , . .

Having said that, L2S requires that your tables have primary keys, as indicated by the error message. After creating the primary key and updating your .DBML accordingly, you should be fine.

Randy

-2
source

Source: https://habr.com/ru/post/1723878/


All Articles