Entity framework


Update Many-to-Many Entities



Download 0,81 Mb.
Pdf ko'rish
bet12/13
Sana18.02.2022
Hajmi0,81 Mb.
#457081
1   ...   5   6   7   8   9   10   11   12   13
Bog'liq
linqentities

Update Many-to-Many Entities 
Connected Scenario:
Following code saves modified Student and Courses (for that student) to the database: 
using
(
var
ctx = 
new
SchoolDBEntities
()) 

Student student = (
from

in
ctx.Students 
where s.StudentName == 
"Student3"

select s).FirstOrDefault(); 
student.StudentName = 
"Updated Student3"

Course cours = student.Courses.FirstOrDefault(); 
//removing course from student
student.Courses.Remove(cours); 
ctx.SaveChanges(); 

 
 
Delete One-to-One Entities 
using
(
var
ctx = 
new
SchoolDBEntities
()) 

Student student = (
from

in
ctx.Students 
where s.StudentName == 
"Student1"
select s).FirstOrDefault()

StudentAddress sAddress = student.StudentAddress; 


21 
ctx.StudentAddresses.DeleteObject(sAddress); 
ctx.SaveChanges(); 

Delete One-to-Many Entities 
Connected Scenario:
Following code deletes the teacher for standard which has One-to-Many relationship from the database in connected 
scenario:
 
using
(
var
ctx = 
new
SchoolDBEntities
()) 

//fetching existing standard from the db
Standard std = (
from

in
ctx.Standards 
where s.StandardName == 
"standard3"
select s).FirstOrDefault(); 
//getting first teacher to be removed
Teacher tchr = std.Teachers.FirstOrDefault(); 
//removing teachers 
if
(tchr != 
null

ctx.Teachers.DeleteObject(tchr);
ctx.SaveChanges(); 

DeleteObject deletes a parent object and also deletes all the child objects in the constraint relationship. 

Download 0,81 Mb.

Do'stlaringiz bilan baham:
1   ...   5   6   7   8   9   10   11   12   13




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish