About Smart Update And Smart Validate

Sep 2, 2008 at 7:10 AM
as we know,The Save Function can judge whether the variable has changed by user, so if user did not change anything, it do not generate the update function, it's great.
but, I used the validate function before save function.
thougth I didn't change anything the validate function still generate a bulk of SQL to check the unique.
so...
In Chinese..
就是说,没有更改任何数据的情况下,验证函数仍然去读取数据库。
这不是一个错误,只是提出来而已,从某种意义上说,这个Smart 判断流程是否在应该validate 的时候也来一遍呢?呵呵。
Sep 2, 2008 at 7:16 AM
Edited Sep 2, 2008 at 7:28 AM
besides, if we think more about validate performance,
I think it should generate the validate sql only if the user changed the varible which has a unique attribute when user execute a update manipulation.
hehe..
就是说从性能角度上说,仅当用户改变了有唯一索引值的时候才应该检查相关唯一索引。

-----------------
顺便借个地方提问一下,你知道怎么在外部扩展你如下的函数么?我继承了LinqObjectModel<T, TKey>一下发现没用。还不太了解为什么没用。没用过这种where T的Class继承方式
namespace Lephone.Linq
{
    [Serializable]
    public class LinqObjectModel<T, TKey> : DbObjectModel<T, TKey> where T : LinqObjectModel<T, TKey>
    {
Sep 2, 2008 at 7:30 AM
Edited Sep 2, 2008 at 7:32 AM
for eg:
I wanna has this function,but i don't wanto broken your class
 public static T FindOne2(int Qid,int Bid)
        {
            return DbEntry.Context.GetObject(CK.K["Qid"]==Qid && CK.K["Bid"]==Bid);
        }
Sep 2, 2008 at 9:06 AM
顺便再提个问题。
就是在给一个BelongsTo 的变量赋值的时候
我知道这个BelongsTo 的ID,我必须先把这个取出来再赋值,能否直接给Id呢?
比如
        [BelongsTo, DbColumn("CategoryId"), Index]
        public abstract Categorys Category { get; set; }

我一般先通过Find找到这个Category ,再赋值
直接赋值d.Category.Id=222
会报错
Sep 2, 2008 at 10:10 AM
------------------------------------------------------------------------------------------------------------------------------------------------------
Coordinator
Sep 3, 2008 at 1:16 AM
It's a little hard for "Smart Validate". I'll think about it.

where T 是泛型约束,可以避免用户出错。eg:
public class MyObjectModel<T, TKey> : LinqObjectModel<T, TKey> where T : MyObjectModel<T, TKey>

确实不允许直接赋值ID给BelongsTo,这个我考虑过,最后还是决定保持这样,一来实现上有困难,二来觉得一般情况下,还是会先读出,做一些其他判断、显示,才做联合,而且,我觉得效率也不会低多少。。。
Sep 3, 2008 at 5:13 AM
Thank you very much!