Sea*_*een 5 c# asp.net-mvc entity-framework entity-framework-6
Files.Name,CreatedDate等.FileBytes.所以我们的模型看起来类似于:
public class FileEntity
{
public string Name { get; set; }
public DateTime CreatedDate { get; set; }
public byte[] FileBytes { get; set; }
// many other fields, most of which we'd like to use
}
Run Code Online (Sandbox Code Playgroud)
FileBytes是null字节本身.FileHasBytes这是一个bool.我如何使用EF6在我的模型类上定义一个字段,该字段将根据表中的另一个字段进行一致投影,而不会拉出该字段的全部内容?
这并不理想,但我认为您可以添加一个返回 QueryExpression 的静态属性,例如
public static Expression<Func<FileEntity,bool>> FileHasBytes
{
get { return ((c)=> c.FileBytes != null && SqlFunctions.DataLength(c.FileBytes)>0)
}
Run Code Online (Sandbox Code Playgroud)
我还没有尝试过这段代码,所以对此持保留态度,所以请尝试彻底测试它。
我前段时间使用 Dynamic.linq 使用过类似的东西,但最近没有尝试过
dbContext.FileEntities.Where("FileHasBytes == true"),
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
125 次 |
| 最近记录: |