locked
Is DbSet.SqlQuery() bugged? RRS feed

  • Question

  •   
      When run the following statement:

        var tasks = iCtx.TaskSet.SqlQuery("select * from SYS_TASK").ToList();

      Got exception, tell me that there is no coresponding column "ParentTaskId" in database.
       
      And my other code like this:
        public class TCommonDbContext : DbContext       
        {

           public DbSet<TpoTask> TaskSet { get; set; }
        }

        [Table("SYS_TASK")]
        public partial class TpoTask
        {
          ....
            [Column("PARENT_TASK_ID")]
            virtual public string ParentTaskId { get; set; }

            [Column("AINDEX")]
            virtual public int? Index { get; set; }

            [Column("BILL_CODE")]
            virtual public string BillCode { get; set; }

            [Column("ATITLE")]
            virtual public String Title { get; set; }
          ...
         }

       the hit point is I used custom mapping columns.
       when I do not use custom mapping column, everything is OK!!!

       Is this the bug? or is there some options I should handle?


    Hello





    Wednesday, June 29, 2011 2:32 AM

Answers

  • Hi again,

    Forgot to mention earlier..

    There is however a workaround you may use if you can do it..

    In your stored procedure, you can alias your PARENT_TASK_ID to ParentTaskId (and do this for all your columns), then it should be able to map it.

     


    --Rune
    • Marked as answer by Jackie-Sun Thursday, June 30, 2011 5:33 AM
    Wednesday, June 29, 2011 7:03 AM
  • hehe.. follow your previous explanation, and after hard struggle and decision, got the same idea as what you said..

    and now come up to share the trick to everybody in puzzle. 

    the temporarily solution is:

     string sql =
    @"
    select
      ...
      PARENT_TASK_ID as ParentTaskId,
      BILL_CODE as BillCode,
      ATITLE as Title,
     ...
    from
      SYS_TASK
    ";


    var tasks = Ctx.TaskSet.SqlQuery(sql).ToList();

    tricks just tricks.
    anticipating the MS quickly and periodcally issues the betas solving somethings.
    (some groups follow Ef in their real projects,   be in delimmas)

    Ef is a great product!

     



    • Marked as answer by Jackie-Sun Thursday, June 30, 2011 5:33 AM
    Thursday, June 30, 2011 3:06 AM

All replies

  • Hi,

    I checked the code in Reflector, and what it seems to do is to call the ObjectContext version of the same function. This in turn doesn't know about the Column attribute (since this is DbContext related) and it's only using the property names.

    For me it seems that this is a bug. I would have reported it to MS using connect.

     


    --Rune
    Wednesday, June 29, 2011 5:48 AM
  • thanks, waiting for the messages...
    Hello
    Wednesday, June 29, 2011 6:17 AM
  • Hi again,

    Forgot to mention earlier..

    There is however a workaround you may use if you can do it..

    In your stored procedure, you can alias your PARENT_TASK_ID to ParentTaskId (and do this for all your columns), then it should be able to map it.

     


    --Rune
    • Marked as answer by Jackie-Sun Thursday, June 30, 2011 5:33 AM
    Wednesday, June 29, 2011 7:03 AM
  • hehe.. follow your previous explanation, and after hard struggle and decision, got the same idea as what you said..

    and now come up to share the trick to everybody in puzzle. 

    the temporarily solution is:

     string sql =
    @"
    select
      ...
      PARENT_TASK_ID as ParentTaskId,
      BILL_CODE as BillCode,
      ATITLE as Title,
     ...
    from
      SYS_TASK
    ";


    var tasks = Ctx.TaskSet.SqlQuery(sql).ToList();

    tricks just tricks.
    anticipating the MS quickly and periodcally issues the betas solving somethings.
    (some groups follow Ef in their real projects,   be in delimmas)

    Ef is a great product!

     



    • Marked as answer by Jackie-Sun Thursday, June 30, 2011 5:33 AM
    Thursday, June 30, 2011 3:06 AM