Is there a performance difference between Model First and Code First in MS Entity Framework 4.1?

前端 未结 3 2004
忘了有多久
忘了有多久 2021-02-06 10:02

I\'m starting a new development and I plan to use Code First in Entity Framework 4.1.

I have previously used Model First and found some performance issues around loadin

3条回答
  •  独厮守ぢ
    2021-02-06 10:35

    Yes, there are performance differences between Model First (EF 4.0) and Code First (EF 4.1 - 4.3.1):

    • You cannot pre-generate internal query views. This means that every time EF tries to run its first query (per app domain), it will need to perform an expensive operation to generate those views, depending on your model complexity. This usually affects application startup performance and can make debugging quite annoying.

    • You cannot use compiled queries. This can seriously affect queries that are used often, especially complex queries. It can become a serious bottleneck and a CPU hog. Only EF 5.0 (that will be included with .NET 4.5) fixes this issue by automatically compiling all queries, including Code First queries.

提交回复
热议问题