Guide to Entity Framework with



Download 11,91 Mb.
Pdf ko'rish
bet35/48
Sana30.03.2022
Hajmi11,91 Mb.
#517122
TuriGuide
1   ...   31   32   33   34   35   36   37   38   ...   48
Bog'liq
Entity Framework Tutorial, Second Edition (1)

[
 29 
]
Now, what were the downsides? You cannot use 
CompiledQuery
using the 
DbContext
API as it only works with 
ObjectContext
. Note that the support for 
compiled query was revoked from the 
DbContext
API due to some technical 
limitations. If you use a code-first strategy, you will most likely be opting for the 
DbContext
API. Thankfully, Entity Framework 6 solved this problem, so you no 
longer need to make this choice.
With Entity Framework 6, you have a feature called 
auto-compiled queries
—this 
works very different from the way 
CompiledQuery
works. You no longer need to 
write code to compile each query and then invoke as needed. How does it work 
then? Entity Framework stores the generated SQL in the cache using a background 
thread and then as and when needed (based on the calls made), it searches the 
compiled queries in the cache. This is illustrated in the following image:
Translate, Store Hash, Store
SQL and Return SQL
Return Hash (from Cache)
LINQ to Entities
Create Hash for the query
Add
Parameters
Is Hash
available?
Database
No
Yes
Auto-compiled query in Entity Framework
You can also turn off 
query caching if you need to. The new 
ObjectContext.
ContextOptions
property allows you to control the default behavior of the query 
compilation. This property is set to 
true
by default, but you can set it to 
false
to 
turn off the auto-compilation of your queries. Here is an example:
dataContext.ContextOptions.DefaultQueryPlanCachingSetting = false;


Introducing the ADO.NET Entity Framework
[
 30 
]
If you are using 
DbContext
, you should cast to 
IObjectContextAdapter,
as shown 
in the following code:
((IObjectContextAdapter)dataContext).ObjectContext.ContextOptions. 
DefaultQueryPlanCachingSetting = false;

Download 11,91 Mb.

Do'stlaringiz bilan baham:
1   ...   31   32   33   34   35   36   37   38   ...   48




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