HTML5¼¼Êõ

EntityFramework CoreÎÊÌâ´¦Àí¼¯½õ£¨Ò»£© - Jeffcky(2)

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

public async Task bool UpdateStatus( int [] ids){ var blogs = _efCoreContext.Blogs.Where(d = ids.Contains(d.Id)); var updateProductList = blogs.Select(b = new Blog() { Id = b.Id, Status = 1 }).ToList

public async Task<bool> UpdateStatus(int[] ids) { var blogs = _efCoreContext.Blogs .Where(d => ids.Contains(d.Id)); var updateProductList = blogs.Select(b => new Blog() { Id = b.Id, Status = 1 }).ToList(); _efCoreContext.UpdateRange(updateProductList, true, d => d.Status); if (await _efCoreContext.SaveChangesAsync(CancellationToken.None) > 0) { return true; } return false; }

´ËʱÓëÊý¾Ý¿â»á½øÐÐÁ½´ÎÁ¬½Ó£¬Ò»´ÎÊDzéѯ£¬Ò»´ÎÊǸüÐÂÖ¸¶¨ÊôÐÔ×ֶΣ¬Í¨¹ýSQL¸ú×ÙÎÒÃÇÄÜ¿´µ½ÈçÏÂÓï¾ä£º

SELECT [d].[Id] FROM [Blog] AS [d] WHERE [d].[Id] IN (2, 3, 5, 6)

exec sp_executesql N'SET NOCOUNT ON; UPDATE [Blog] SET [Status] = @p0 WHERE [Id] = @p1; SELECT @@ROWCOUNT; UPDATE [Blog] SET [Status] = @p2 WHERE [Id] = @p3; SELECT @@ROWCOUNT; UPDATE [Blog] SET [Status] = @p4 WHERE [Id] = @p5; SELECT @@ROWCOUNT; UPDATE [Blog] SET [Status] = @p6 WHERE [Id] = @p7; SELECT @@ROWCOUNT; @p1 int,@p0 tinyint,@p3 int,@p2 tinyint,@p5 int,@p4 tinyint,@p7 int,@p6 tinyint',@p1=2,@p0=1,@p3=3,@p2=1,@p5=5,@p4=1,@p7=6,@p6=1

×îÖÕÕýÈ·¸üÐÂÈçÏ£º

³ýÁËÉÏÊöͨ¹ýд·´ÉäÀ©Õ¹·½·¨À´¸üÐÂÍâÊôÐÔÍ⣬һֱÔÚÏë×ÅÆäÖлá½øÐÐÁ½´ÎÊý¾Ý¿âÁ´½Ó£¬½øÐÐÒ»´ÎÊý¾Ý¿âÁ´½Ó±È½ÏºÄʱ£¬Õâ¸öʱºòÏëµ½µÄÖ»ÄÜÖ´ÐÐSQLÃüÁîÁË¡£

ÅúÁ¿¸üÐÂÖ®SQLÃüÁî

ÀûÓÃWHERE ....INÀ´½øÐиüУ¬´ËʱSQL¸üдúÂëÔòÈçÏ£º

public async Task<bool> UpdateStatus(int[] ids) { , ids); , CancellationToken.None, testIds); if (effctRow > 0) { return true; } return false; }

²»ÖªµÀ¸÷λ¿´¿Í·¢ÏÖʲôûÓУ¬ÉÏÊöµÄ´úÂëÊÇÓÐÎÊÌâµÄ£¬ÄÄÀïÓÐÎÊÌ⣬²»ÖªµÀµÄÇë¿´Èç϶¯Ì¬ÑÝʾ¡£

 

Õý³£Çé¿öÏÂWHERE...IN(2,3,5,6)¶ø·ÇÉÏÊö“2,3,5,6”£¬´ËʱÎÒ½«ÉÏÊö´úÂëÐÞ¸ÄΪÈçÏ£º

public async Task<bool> UpdateStatus(int[] ids) { var blogIds = string.Empty; foreach (var id in ids) { blogIds += $; } blogIds = blogIds.TrimEnd(); , CancellationToken.None, blogIds); if (effectRows > 0) { return true; } return false; }

´ËʱÔÙÀ´¿´¿´ÑÝʾЧ¹û£º

´ËʱÔò±¨NVARCHARת»»µ½INTʧ°Ü£¬ÄÇô´Ö±©Ò»µã½«idת»»ÎªNVARCHAR:

, CancellationToken.None, blogIds);

µ±È»ÈçÉÏÉæ¼°µ½Ë÷Òý£¬Í¨¹ýº¯Êýת»»²»»á×ßË÷Òý£¬ÎÒÃÇÕý³£Çé¿öÏÂÓ¦¸ÃÊǶ¨ÒåÒ»¸ö±äÁ¿½«id½øÐÐת»»£¬È»ºóÀûÓñäÁ¿À´½øÐаüº¬¡£´ËʱÔÙÀ´¿´ÑÝʾЧ¹û£º

´Ëʱѹ¸ù¶¼Ã»È¥¸üУ¬ÎÒÒ²ÊÇ×íÁË£¬×îºóÎÒÃÇÔÙÀ´¿´Ò»ÖÖÇé¿ö£¬ÎÒÃÇдSQLÃüÁîͨ¹ýÆ´½ÓµÄÐÎʽÀ´½øÐУ¬ÈçÏ£º

, CancellationToken.None);

´Ëʱ¾ÓÈ»¸üгɹ¦ÁË£¬ÆäʵÎÒÃÇÀûÓÃÉÏÊö×Ö·û´®Æ´½ÓµÄ·½Ê½½øÐÐÈçÏÂÁ½ÖÖת»»¶¼»á¸üгɹ¦£º

¡¡

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

Ïà¹ØÎÄÕÂ
  • ´øÄã¿ìËÙ½øÈë.net coreµÄÊÀ½ç - Å©ÂëÒ»Éú

    ´øÄã¿ìËÙ½øÈë.net coreµÄÊÀ½ç - Å©ÂëÒ»Éú

    2017-08-07 10:02

  • ½â¾ö°Ù¶È¸»Îı¾±à¼­Æ÷ UEditor ²åÈëÊÓƵºóûÓз¾¶µÄÎÊÌâ - ÎÒÃǶ¼ÊdzÌÐòÔ³

    ½â¾ö°Ù¶È¸»Îı¾±à¼­Æ÷ UEditor ²åÈëÊÓƵºóûÓз¾¶µÄÎÊÌâ - ÎÒÃǶ¼ÊÇ

    2017-08-02 13:00

  • Entity Framework Core Ö´ÐÐSQLÓï¾äºÍ´æ´¢¹ý³Ì - Sweet-Tang

    Entity Framework Core Ö´ÐÐSQLÓï¾äºÍ´æ´¢¹ý³Ì - Sweet-Tang

    2017-08-02 08:00

  • .NET Core ³É¶¼ÏßÏÂÃæ»ù»áÀ­¿ªÐòÄ» - Savorboard

    .NET Core ³É¶¼ÏßÏÂÃæ»ù»áÀ­¿ªÐòÄ» - Savorboard

    2017-08-01 10:02

ÍøÓѵãÆÀ
²