EF基礎知識小記四 資料庫 模型設計器

2022-01-14 18:20:29 字數 2431 閱讀 3602

ef基礎知識小記三(設計器=>資料庫)介紹了如何建立乙個空設計器模型,並如何將模型同步到資料庫的表中,本文則主要介紹如何將乙個存在的資料庫同步到模型設計器中。為了能快速的模擬這個過程,給出一下建表語句,**如下:

--

建表指令碼

create

table

student

( id

intnot

null

, name

varchar(30) not

null

, age

intnot

null

)create

table

teacher

( id

intnot

null

, name

varchar(30) not

null

, age

intnot

null

)create

table

studentteacher

( studentid

intnot

null

, teacherid

intnot

null

)create

table

infocard

( id

intnot

null

,

[money

]int

notnull

, studentid

intnot

null)--

給表新增約束

--單主鍵約束

alter

table student add

constraint

[pk_people

]primary

keyclustered (id asc

)alter

table infocard add

constraint

[pk_infocard

]primary

keyclustered (id asc

)alter

table teacher add

constraint

[pk_teacher

]primary

keyclustered (id asc)--

雙主鍵約束(多對多)

alter

table studentteacher add

constraint

[pk_studentteacher

]primary

keyclustered (studentid,teacherid asc)--

雙外來鍵約束(多對多)

alter

table

studentteacher

addconstraint

[fk_studentteacher_student

]foreign

key (studentid) references student (id) on

delete no action on

update no action --

級聯更新級聯刪除

alter

table studentteacher add

constraint

[fk_studentteacher_teacher

]foreign

key (teacherid) references teacher (id) on

delete no action on

update

no action

--但外來鍵約束(一對多)

alter

table infocard add

constraint

[fk_infocard_student

]foreign

key (studentid) references student (id) on

delete no action on

update no action

1、看過ef基礎知識小記三(設計器=>資料庫)後,省去一些簡單的操作步驟,直接到下面這步操作

根據資料庫生成edmx

2、選擇指定的資料庫,並選擇響應的表生成edmx模型設計器

3、點選確認,生成成功,如下圖:

4、增刪查該的操作和ef基礎知識小記三(設計器=>資料庫)介紹的一樣

Linq基礎知識小記四之操作EF

1 ef簡介 ef之於linq,ef是一種包含linq功能物件關係對映技術.ef對資料庫架構和我們查詢的型別進行更好的解耦,使用ef,我們查詢的物件不再是c 類,而是更高層的抽象 entity data model,這提供了額外的靈活性,但在效能和簡單性上面也會有所損失.ef的優點 在資料庫架構和實...

資料庫基礎知識

資料定義 定義基本表 create table 表名 列名 資料型別 列級完整性約束條件 列名 資料型別 列級完整性約束條件 表級完整性約束條件 後面用到的表 1 學生 表 student 由學號 sno 姓名 sname 性別 s 年齡 sage 所在系 sdept 5個屬性組成,可記為 stud...

資料庫 基礎知識

e r模型 實體 聯絡模型 entity relationship model,e r模型 實體是指現實中區別於其他物件的一種 物體 或一件 事情 例如一名學生,乙個專案等等。同乙個型別中所有的實體被叫做實體集,對應於資料庫的一張表,乙個實體則對應於一條記錄。不同的任務之間,就是通過聯絡關係整合到一...