LINQ2SQL图像保存问题 [英] linq2sql image saving problems
问题描述
我有一个对象,它有一个属性:
I have an object that has a property:
[Column]
public Binary Image { get; set; }
当对象被保存在第一时间每天这是确定的,但是当它被修改,我得到的SubmitChanges异常:
When the object is saved the first time every this is OK, but when it is modified I get an exception on SubmitChanges:
中的数据类型的图像和 VARBINARY(最大)是不相容的,在 等于操作员
The data types image and varbinary(max) are incompatible in the equal to operator.
可能是什么问题就在这里?
What might be the problem here?
推荐答案
您是否获得了,异常?问题是,LINQ2SQL要检查,以确保它应该修改列之前,它实际上修改它。我通常不关心我和我心甘情愿更新整个行,所以我就把 UpdateCheck的= UpdateCheck.Never
命名的参数在我的 ColumnAttributes
。即,
Are you getting the, "" exception? The problem is that linq2sql wants to check to make sure it should modify the column before it actually modifies it. I usually don't care as much and am perfectly happy updating the entire row so I put the UpdateCheck = UpdateCheck.Never
named parameter in my ColumnAttributes
. I.e.,
[Column(UpdateCheck = UpdateCheck.Never)]
然后,当我想保存的项目,我只是这样做:
Then, when I want to save the item, I just do this:
Table<TEntity> da = MyDataContext.Context.GetTable<TEntity>();
if (entity.Id > 0)
da.Attach(entity, true);
else
da.InsertOnSubmit(entity);
da.Context.SubmitChanges();
这篇关于LINQ2SQL图像保存问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!