Bugs When Where Conditions Contains a "BelongsTo-Type"

Topics: Developer Forum
Sep 8, 2008 at 3:13 PM

                First define this table

#region Test

    [Serializable]
    public abstract class TableA : LinqObjectModel<TableA>
    {
        public abstract string Name { get; set; }
    }

    [Serializable]
    public abstract class TableB : LinqObjectModel<TableB>
    {
        [Index(UNIQUE = true, IndexName = "Url_TableAId", ASC = false)]
        public abstract string Url { get; set; }

        [Index(UNIQUE = true, IndexName = "Url_TableAId", ASC = false)]
        [BelongsTo, DbColumn("TableAId")]
        public abstract TableA TB { get; set; }
    }

   
    #endregion

// and then


                DbContext de = DbEntry.Context;
                de.DropAndCreate(typeof(TableA));
                de.DropAndCreate(typeof(TableB));

                var t1 = TableA.New();
                t1.Name = "Test1";
                t1.Save();

                var t2 = TableB.New();
                t2.Url = "TUrl1";
                t2.TB = t1;
                t2.Save();

                var t3 = TableB.New();
                t3.Url = "TUrl2";
                t3.TB = t1;
                t3.Save();

                var t4 = TableB.FindOne(p => p.Url == "TUrl1" && p.TB.Id == 1);

//Trace,,SQL,Select [Id],[Url],[TableAId] From [TableB] Where ([Url] = @Url_0) And ([Id] = @Id_1);
<Text><60>(@Url_0=TUrl1:String,@Id_1=1:Int64),

Here"([Id] = @Id_1);" is wrong ,it should be "TableAId"


                var t5 = TableB.FindOne(p => p.Url == "TUrl2" && p.TB.Id == 1);

//Trace,,SQL,Select [Id],[Url],[TableAId] From [TableB] Where ([Url] = @Url_0) And ([Id] = @Id_1);
<Text><60>(@Url_0=TUrl2:String,@Id_1=1:Int64),

Here"([Id] = @Id_1);" is wrong ,it should be "TableAId"

             var t8=TableA.FindById(1);

                var t6 = TableB.FindOne(p => p.Url == "TUrl2" && p.TB == t8);

//here throw
The given key was not present in the dictionary.System.Collections.Generic.KeyNotFoundException

Sep 8, 2008 at 3:14 PM
though I can use the CK.K instead. :)