当我使用SaveChanges保存实体并仅保存有效字段时,是否可以跳过无效值?
跳过实体级别非常简单,但我无法在字段级别找到这样做的方法。
答案 0 :(得分:1)
/// <summary>
/// Reads all available bytes from reader
/// </summary>
/// <param name="reader"></param>
/// <param name="ordinal"></param>
/// <returns></returns>
private byte[] GetBytes(SqliteDataReader reader, int ordinal)
{
byte[] result = null;
if (!reader.IsDBNull(ordinal))
{
long size = reader.GetBytes(ordinal, 0, null, 0, 0); //get the length of data
result = new byte[size];
int bufferSize = 1024;
long bytesRead = 0;
int curPos = 0;
while (bytesRead < size)
{
bytesRead += reader.GetBytes(ordinal, curPos, result, curPos, bufferSize);
curPos += bufferSize;
}
}
return result;
}