How to query Code First entities based on rowversion/timestamp value?

前端 未结 10 1147
忘了有多久
忘了有多久 2020-12-14 17:56

I\'ve run into a case where something that worked fairly well with LINQ to SQL seems to be very obtuse (or maybe impossible) with the Entity Framework. Specifically, I\'ve g

10条回答
  •  借酒劲吻你
    2020-12-14 18:32

    I found this workaround usefull:

    byte[] rowversion = BitConverter.GetBytes(revision);
    
    var dbset = (DbSet)context.Set();
    
    string query = dbset.Where(x => x.Revision != rowversion).ToString()
        .Replace("[Revision] <> @p__linq__0", "[Revision] > @rowversion");
    
    return dbset.SqlQuery(query, new SqlParameter("rowversion", rowversion)).ToArray();
    

提交回复
热议问题