Programming techniques

about every things that i''m learning and want learn to other people

Programming techniques

about every things that i''m learning and want learn to other people

مقایسه کارایی NHibernate با Entity Framework

NHibernate vs Entity Framework performance

مقایسه سطوح

  • store
  • read over relations
  • read by ID
  • update
  • delete

    Operation \ Number of operations

    NHiberante – 4K

    Entity Framework – 4K

    NHiberante – 40K

    Entity Framework- 40K

    Winner

    Store

    37,37

    9,19

    1500

    98

    Entity Framework

    Read over relations

    1,01

    0,54

    10,13

    4,18

    Entity Framework

    Read by ID

    3,06

    25,22

    246

    230

    NHibernate with smaller amount of objects

    Update

    6,61

    7,34

    77

    72

    Both

    Delete

    3,35

    16,76

    58

    1824

    NHibernate

     

     دوستان عزیز با توجه به جدول بالا کیفیت آیاNHibernate  با توجه به سرعتی که در خواندن دیتا دارد

    پر اهمیت تر است یا Entity Framework که  در خواندن relation ها سریعتر است ؟

    از دید یکی از دوستان Read by ID در زدن query های پیچیده پر اهمیت تر است و سرعت ذخیره و به روز رسانی دیتا ها نسبت به آن از اهمیت کمتری برخوردار است .

    دوستان عزیز لطفا نظر خود را در این باره برای من بنویسید .

    مرجع:

    http://gregdoesit.com/2009/08/nhibernate-vs-entity-framework-a-performance-test/

     

    مشکلات EF4

    Update: I haven't used Entity Framework since version 4.0 much, so my answer can be outdated.

    Actually is pretty easy to compare them when you have used both. There are some serious limitations with EF4, I can name some which I encountered by my self:

    EF4 problems:

    • Eager Loading and shaping the result: EF4 eager loading system (Include("Path")) generates improper SQL, with looping JOIN's , which will execute thousands(not literally) time slower for many-to-many relationships then hand written SQL (it's effectively unusable).
    • Materializer can't materialize associated entities: If you can think you can overcome previous problem by providing you own SQL query, you are wrong. EF4 can't materialize(map) associated entities from JOIN SQL query, it can only load data from one table (So if you have Order.Product, SELECT * FROM order LEFT JOIN Product will initialize only Order object, Product will remain null, thought all necessary data is fetched in query to init it ). This can be overcome by using EFExtensions community add-on, but the code you will have to write for this is really ugly (I tried).
    • Self-Tracking Entities: Many say that Self-tracking entities are cool for N-tier development including the top answer in this thread. Thought I haven't even give them a try, I can say they are not.Every input can be forged, you can't simply take the changes that user sends you and apply them to data base, why not give the user direct data base access then? Any way you will have to load the data user is about to change from DB, check that it exist|not exists do permissions checks etc etc. You can't trust user on the state of entity he is sending to server, you will anyway have to load this entity from DB and determine it's state and other things, so this information is useless, as do Self-Tracking entities unless you do a private trusted n-tier system for internal use, in which case maybe you could give just plain DB access. (Thats my thoughts about ST Entities and N-tire, I'm not very expericned in N-Tier, so it can change, if I misunderstood something here comment it)

    • Logging, Events, integrating business logic: EF4 is like black box, it do something and you have no idea what it do. There is only one event OnSavingChanges where you can put some business logic you need to run before something happens with DB, and if you need to apply some changes to business objects before something happens you will have to dig in ObjectStateManager, and this is really ugly, code can become huge. If you for example using Repository pattern and what to be notified on changes made to DB in clean object way, you will have hard time doing this with EF.

    • Extensibility: All EF code is private and internal, if you don't like something (and you will not like a LOT if you are serious about EF using), no way you will change this in easy way, In fact I'm sure it's easer to write you own ORM from scratch (I did) then make EF work as you need. As example take a look at EFExtensions source, it's based on extensions methods, and different "hacks" to make EF little more usable, and the code is pretty ugly (and it's not authors fault, when everything in EF is private this is the only way to extend it).

    I can continue to write bad things about EF and how painful it was for me to work with it for like 20 pages, and maybe I will.

    What about NHibernate? It's absolutely different level, it's like comparing PHP to C#, EF4 is like in Stone-age, it's like EF is 10 years behind then NHibernate in development progress, and in fact it is, Hibernate was started in 2001. If you have free time to learn and switch on Nhibernate, do it.

     Write By:Alex Burtsev in stackoverflow Site with 28 vote

  • نظرات 1 + ارسال نظر
    سعید پنج‌شنبه 16 خرداد‌ماه سال 1392 ساعت 10:17 ق.ظ

    - مطلبی که لینک دادید قدیمی است. مربوط به 2009 است.
    - ایراداتی هم که ذکر شده اخیرا تمامشون برطرف شدن. مثلا به Ef6 beta الان مباحث logging توکار اضافه شده. یا Self-Tracking Entities کلا منسوخ شده جاش WCF Data Services با EF هماهنگ شده. بحث توسعه پذیری با سورس باز شدن EF برطرف شده. EF در سال‌های قبل سورس باز نبود.

    خیلی جالب مرسی که مارو هم از تغییرات مطلع کردین خوشحال می شم اکه مطلب بیشتری در این باره در اختیارمون قرار بدین

    برای نمایش آواتار خود در این وبلاگ در سایت Gravatar.com ثبت نام کنید. (راهنما)
    ایمیل شما بعد از ثبت نمایش داده نخواهد شد