BLToolkit:尝试更新实体并收到“无法转换为 SQL 错误”
我有一个更新方法:
protected int ProcessUpdate(TUpdateDto updateDto, Func<IQueryable<TEntity>, IUpdateable<TEntity>> firstSetter, params Func<IUpdateable<TEntity>, IUpdateable<TEntity>>[] setters)
{
Checker.AssertNull(updateDto);
int id = updateDto.Id.FailIfNull();
IQueryable<TEntity> query = from item in new Table<TEntity>()
where item.Id == id
select item;
IUpdateable<TEntity> updateable = firstSetter(query);
foreach (var setter in setters)
{
setter(updateable);
}
Checker.AssertNull(updateable);
updateable.Update();
return id;
}
和实体:
[TableName("Test")]
public class Test
{
[PrimaryKey, Identity]
public int Id { get; set; }
public string Field1 { get; set; }
}
这是更新代码:
ProcessUpdate(updateDto, x => x.Set(e => e.Id, updateDto.Id),
x => x.Set(e => e.Field1, updateDto.Field1));
当我尝试更新表中的条目时,我得到“'Convert(item).Id'无法转换为 SQL”。错误。我尝试过不更新 id,结果是一样的。我希望我能找到解决方案,但我找不到。感谢您的回答。
I have an update method:
protected int ProcessUpdate(TUpdateDto updateDto, Func<IQueryable<TEntity>, IUpdateable<TEntity>> firstSetter, params Func<IUpdateable<TEntity>, IUpdateable<TEntity>>[] setters)
{
Checker.AssertNull(updateDto);
int id = updateDto.Id.FailIfNull();
IQueryable<TEntity> query = from item in new Table<TEntity>()
where item.Id == id
select item;
IUpdateable<TEntity> updateable = firstSetter(query);
foreach (var setter in setters)
{
setter(updateable);
}
Checker.AssertNull(updateable);
updateable.Update();
return id;
}
And entity:
[TableName("Test")]
public class Test
{
[PrimaryKey, Identity]
public int Id { get; set; }
public string Field1 { get; set; }
}
And here is the update code:
ProcessUpdate(updateDto, x => x.Set(e => e.Id, updateDto.Id),
x => x.Set(e => e.Field1, updateDto.Field1));
When I try to update an entry in a table I get "'Convert(item).Id' cannot be converted to SQL." error. I have tried not to update id and results were the same. I wish I could find the solution, but I can not. Thanks for your answers.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
解决方案是修改 BLToolkit 源。
The solution was about modifying BLToolkit sources.