c# - CTP5 EF Code First vs. Linq-to-sql -
okay, know have doing wrong here because performance times i'm getting different shocking. i've been considering using code first option of entity in existing project of mine i've been trying performance test see how compares. i'm using mspec run tests against remote development database.
here tests:
public class query_a_database_for_a_network_entry_with_linq : ipmanagement_object { protected static netinfo.ipm_networkmaster result; because of = () => { var db = new netinfodatacontext(); result = db.ipm_networkmasters.singleordefault(c => c.networkid == 170553); }; should_return_an_ipm_networkmaster_object = () => { result.shouldbeoftype(typeof(netinfo.ipm_networkmaster)); }; should_return_a_net_ou_object_with_a_networkid_of_4663 = () => { result.ipm_ouidmaps.first().net_ou.net_ouid.shouldequal(4663); };
}
public class query_a_database_for_a_network_entry_with_entity_code_first : ipmanagement_object { protected static netinfo.core.models.ctp.ipm_networkmaster result; because of = () => { netinfo.core.models.ctp.netinfodb db = new netinfo.core.models.ctp.netinfodb(); result = db.ipm_networkmasters.singleordefault(c => c.networkid == 170553); }; should_return_an_ipm_networkmaster_object = () => { result.shouldbeoftype(typeof(netinfo.core.models.ctp.ipm_networkmaster)); }; should_return_a_net_ou_object_with_a_networkid_of_4663 = () => { result.net_ous.first().net_ouid.shouldequal(4663); }; }
as can see datacontext linq-to-sql can't access object directly have many many relationship. have use intermediate lookup table. 1 of things entity framework. when run these test linq test never takes longer 4 seconds complete (database remote). entity test takes 8 seconds every time. not sure why there such huge difference?? here excerpts of poco classes , dbcontext:
dbcontext:
public class netinfodb : dbcontext { public netinfodb() : base("netinfoconnectionstring") { } public dbset<ipm_networkmaster> ipm_networkmasters { get; set; } public dbset<ipm_networktype> ipm_networktypes { get; set; } public dbset<net_ou> net_ous { get; set; } protected override void onmodelcreating(system.data.entity.modelconfiguration.modelbuilder modelbuilder) { modelbuilder.entity<ipm_networkmaster>() .hasmany(a => a.net_ous) .withmany(b => b.ipm_networkmasters) .map(m => { m.maprightkey(a => a.net_ouid, "net_ouid"); m.mapleftkey(b => b.networkid, "networkid"); m.totable("ipm_ouidmap"); }); } }
ipm_networkmaster:
public class ipm_networkmaster { public int networkid { get; set; } <snip> public virtual icollection<net_ou> net_ous { get; set; } }
net_ou:
public class net_ou { public int net_ouid { get; set; } <snip> public virtual icollection<ipm_networkmaster> ipm_networkmasters { get; set; } }
as has mentioned, need profile queries. assuming using sql server, can spool sql server profiler , compare queries , execution plans.
as performance issue, must measure first. scenario, have more. have measure twice each technology , make sure comparing apples apples. if can rule out sql being generated have measure application code, possibly rule bottlenecks there.
i suspect generated queries though.
Comments
Post a Comment