HTML5¼¼Êõ

EntityFramework Core²»µÃ²»×¢ÒâµÄÐÔÄÜÓÅ»¯ÒâÍâÊÕ»ñ£¬Äã»áÓÃ´í£¿ - Jeffcky

×ÖºÅ+ ×÷ÕߣºH5Ö®¼Ò À´Ô´£ºH5Ö®¼Ò 2017-04-05 14:00 ÎÒÒªÆÀÂÛ( )

Ç°ÑÔ ÕâÁ½ÌìÔÚ×ÅʵÑо¿EF CoreÏîÄ¿µ±ÖжÔÓÚһЩ²éѯҲûʵ¼ÊÈ¥¼ì²â£¬ÓÚÊÇÏë×ÅÀûÓ÷żÙʱ¼äȥʵ¼Ê²âÊÔÏ£¬½á¹û±¾ÎľͳöÀ´ÁË£¬too young,too simple£¬ºóÐø²©Ö÷»á´Óµ×²ã·­Òë±í´ïʽÊ÷ŪÆð£¬À´´ÓÔ´Í·Á˽âEF Core£¬Í¨¹ý±¾ÎÄÄã»áÃ÷°×²»ÊÇEF CoreÍŶÓû×öÐÔÄÜÓÅ»¯£¬¶ø

Ç°ÑÔ

ÕâÁ½ÌìÔÚ×ÅʵÑо¿EF CoreÏîÄ¿µ±ÖжÔÓÚһЩ²éѯҲûʵ¼ÊÈ¥¼ì²â£¬ÓÚÊÇÏë×ÅÀûÓ÷żÙʱ¼äȥʵ¼Ê²âÊÔÏ£¬½á¹û±¾ÎľͳöÀ´ÁË£¬too young,too simple£¬ºóÐø²©Ö÷»á´Óµ×²ã·­Òë±í´ïʽÊ÷ŪÆð£¬À´´ÓÔ´Í·Á˽âEF Core£¬Í¨¹ý±¾ÎÄÄã»áÃ÷°×²»ÊÇEF CoreÍŶÓû×öÐÔÄÜÓÅ»¯£¬¶øÊÇÄã¸ù±¾¾ÍûÓùý¶øÇÒÕýÔÚµ¹ÍË¡£

EntityFramework CoreÐÔÄÜÓÅ»¯³õ̽

¼òµ¥´Ö±©Ö±½ÓÉÏ´úÂ룬¸ø³öÉÏÏÂÎÄÒÔ¼°ÐèÒªÓõ½µÄ²âÊÔÀ࣬ÈçÏ£º

public class EFCoreContext : DbContext { public DbSet<Blog> Blogs { get; set; } OnConfiguring(DbContextOptionsBuilder optionsBuilder) => optionsBuilder.UseSqlServer(); OnModelCreating(ModelBuilder modelBuilder) { modelBuilder.Entity<Blog>(pc => { pc.ToTable().HasKey(k => k.Id); pc.Property(p => p.Name).IsRequired(); pc.Property(p => p.Url).IsRequired(); pc.Property(p => p.Count).IsRequired(); pc.Property(p => p.RowVersion).IsRequired().IsRowVersion().ValueGeneratedOnAddOrUpdate(); }); } }

ÄãÊÇ·ñÏñÈçÏÂÈ¥»ñÈ¡·ÖÒ³Êý¾ÝÄØ£¬ÎÒÃÇÀ´Ò»ÆðÇÆÇÆ£º

var ef = new EFCoreContext(); var blogs = ef.Blogs; var example1 = blogs .Skip(1) .Take(1) .ToList(); var example2 = blogs .Skip(10) .Take(10) .ToList();

ÎÒÃÇͨ¹ýÈçÏÂSQLÓï¾äÀ´²é¿´²éѯ¼Æ»®Éú³ÉµÄSQLÓï¾ä£º

SELECT sys.syscacheobjects.cacheobjtype, sys.dm_exec_query_stats.execution_count, sys.syscacheobjects.SQL, sys.dm_exec_query_plan.query_plan FROM sys.dm_exec_query_stats INNER JOIN sys.dm_exec_cached_plans ON sys.dm_exec_cached_plans.plan_handle = sys.dm_exec_query_stats.plan_handle INNER JOIN sys.syscacheobjects ON sys.syscacheobjects.bucketid = sys.dm_exec_cached_plans.bucketid CROSS APPLY sys.dm_exec_query_plan(sys.dm_exec_query_stats.plan_handle)

½á¹ûÈçÏ£º

ÎÒÃÇÔÙÀ´¿´¿´xmlÎļþÖÐÉú³ÉµÄSQLÓï¾äÊÇÔõÑùµÄ¡£

Õâ˵Ã÷ʲôÎÊÌâÄØ£¬ÉÏÊö²éѯ¼Æ»®ÖÐÉú³ÉµÄSQLÓï¾ä¶ÔÓÚÎÒÃÇÉÏÊöȥȡÊý¾ÝÊ×Ñ¡´ÓµÚ¶þÌõÈ¡Ò»Ìõ£¬½ÓÏÂÀ´ÊÇȥȡµÚÊ®ÌõºóµÄÊ®Ìõ£¬Í¬Ê±ÉÏÊöSQLÓï¾ä¶øÊÇÉùÃ÷ÁËÁ½¸ö±äÁ¿£¬»»ÑÔÖ®£¬ÉÏÊöÁ½ÌõÓï¾ä²éѯ×îÖÕÔÚµÚÒ»´Î²éѯºóSQL²éѯ¼Æ»®½øÐÐÁË»º´æ£¬Ï´ÎÔÙȥȡÊý¾Ýʱֱ½Óµ÷ÓôËSQLÓï¾äÒÔ´Ë´ïµ½ÖØÓõÄÄ¿µÄ£¬ÏÂÃæÒªÊÇÎÒÃǽøÐÐÈçϸÄÔ죬½á¹û»áÔõÑùÄØ£¿

var ef = new EFCoreContext(); var blogs = ef.Blogs; var count = 1; var example1 = blogs .Skip(count) .Take(count) .ToList(); count = 10; var example2 = blogs .Skip(count) .Take(count) .ToList();

½á¹û¾­¹ýÉÏÊö¸ÄÔìÀûÓñäÁ¿µÄÐÎʽºÍÖ±½Ó¸³ÖµµÄÐÎʽÊÇÒ»Öµģ¬Ã»ÓÐʲô¿É½²µÄ£¬ÏÂÃæÎÒÃÇÔÙÀ´½²ÊöÁíÍâÒ»ÖÖÇé¿ö¡£Çë¼ÌÐøÍùÏ¿´¡£

var ef = new EFCoreContext(); var blogs = ef.Blogs; var skipTakeWithInt1 = blogs .OrderBy(b => b.Id).Where(d => d.Name.Length > 1).ToList(); var skipTakeWithInt2 = blogs .OrderBy(b => b.Id).Where(d => d.Name.Length > 10).ToList();

¿´³öʲôûÓУ¬¶ÔÓÚÉÏÊöÁ½Ìõ²éѯÔòÊǶÔÓ¦½øÐÐÁËÁ½´ÎSQL²éѯ£¬ÕâÏÂÒâʶµ½ÁËÆäÖÐÐþ»úÁË°É£¬ÏÂÃæÎÒÃǽ«ÉÏÊöÔÙ¸ÄÔìһϣº

var ef = new EFCoreContext(); var blogs = ef.Blogs; var length = 1; var skipTakeWithVariable1 = blogs .OrderBy(b => b.Id).Where(d => d.Name.Length > length).ToList(); length = 10; var skipTakeWithVariable2 = blogs .OrderBy(b => b.Id).Where(d => d.Name.Length > length).ToList();

¡¡

1.±¾Õ¾×ñÑ­ÐÐÒµ¹æ·¶£¬ÈκÎתÔصĸå¼þ¶¼»áÃ÷È·±ê×¢×÷ÕߺÍÀ´Ô´£»2.±¾Õ¾µÄÔ­´´ÎÄÕ£¬ÇëתÔØʱÎñ±Ø×¢Ã÷ÎÄÕÂ×÷ÕߺÍÀ´Ô´£¬²»×ðÖØÔ­´´µÄÐÐΪÎÒÃǽ«×·¾¿ÔðÈΣ»3.×÷ÕßͶ¸å¿ÉÄܻᾭÎÒÃDZ༭Ð޸Ļò²¹³ä¡£

Ïà¹ØÎÄÕÂ
  • EntityFramework Core²¢·¢ÉîÍÚÏê½â£¬Ò»Ö½³¤ÎÄ£¬Äã×¼±¸ºÃ¿´ÍêÁËÂ𣿠- Jeffcky

    EntityFramework Core²¢·¢ÉîÍÚÏê½â£¬Ò»Ö½³¤ÎÄ£¬Äã×¼±¸ºÃ¿´ÍêÁËÂ𣿠-

    2017-04-05 14:03

  • ASP.NET Core MVC Ô´Âëѧϰ£ºÏê½â Action µÄÆ¥Åä - Savorboard

    ASP.NET Core MVC Ô´Âëѧϰ£ºÏê½â Action µÄÆ¥Åä - Savorboard

    2017-03-30 18:02

  • ASP.NET Core MVC Ô´Âëѧϰ£ºMVC Æô¶¯Á÷³ÌÏê½â - Savorboard

    ASP.NET Core MVC Ô´Âëѧϰ£ºMVC Æô¶¯Á÷³ÌÏê½â - Savorboard

    2017-03-27 18:01

  • Ò»·Ý¹ØÓÚ×齨.NET Core¿ªÔ´ÍŶӵij«ÒéÊé - ÅíÔó0902

    Ò»·Ý¹ØÓÚ×齨.NET Core¿ªÔ´ÍŶӵij«ÒéÊé - ÅíÔó0902

    2017-03-13 17:02

ÍøÓѵãÆÀ
®