Bug Report IDbObject Mkey isdbgenerate=false Update

Jan 12, 2009 at 2:45 PM

    public class test_table : IDbObject
    {
        [Length(2)]
        [DbKey(IsDbGenerate = false)]
        public string k1;

        [Length(2)]
        [DbKey(IsDbGenerate = false)]
        public string k2;

    }

         DbEntry.Context.DropAndCreate(typeof(test_table));

            test_table tb1= new test_table();
            tb1.k1 = "01";
            tb1.k2 = "01";

            DbEntry.Insert(tb1);

            var o=DbEntry.GetObject<test_table>(CK.K["k1"] == "01" && CK.K["k2"] == "01");

            o.k2 = "05";

            DbEntry.Update(o);

it will generate wrong sql:

{Update [test_table] Set [k2]=@k2_0,[k1]=@k1_1  Where ([k1] = @k1_2) And ([k2] = @k2_3);
<Text><30>(@k2_0=05:String,@k1_1=01:String,@k1_2=01:String,@k2_3=05:String)}

it shoud be

{Update [test_table] Set [k2]=@k2_0,[k1]=@k1_1  Where ([k1] = @k1_2) And ([k2] = @k2_3);
<Text><30>(@k2_0=05:String,@k1_1=01:String,@k1_2=01:String,@k2_3=01:String)}

Coordinator
Jan 13, 2009 at 1:42 AM
You should NOT change the primary key since the key is the only identity of an record.
It's not an update opration, for this, you should remove the old one and insert the new one.
Jan 13, 2009 at 1:52 AM
Edited Jan 13, 2009 at 1:58 AM
it's not a good solution...

even delete you should give dbentry a method to automatic process this situation.

you can run this 

{Update [test_table] Set [k2]=@k2_0,[k1]=@k1_1  Where ([k1] = @k1_2) And ([k2] = @k2_3);
<Text><30>(@k2_0=05:String,@k1_1=01:String,@k1_2=01:String,@k2_3=01:String)}


why don't you generate it?
Coordinator
Jan 13, 2009 at 4:53 AM
Because you define them as primary key, if they are PK they should never changed!
And I don't store anything like 01 since you already changed it to 05, so I don't know it was 01 before.
If in your model you need change the value of them, then they should be normal columns but not PK.
Just add a auto-inc column as PK and make k1 k2 as union-index is the right solution for my opinion.