The EntitySpaces Community

Share and learn about the EntitySpaces Architecture.
Welcome to The EntitySpaces Community Sign in | Join | Help
in
Home Forums Photos

Problem binding to query when joined field is null

Last post 06-30-2008, 8:40 AM by PurpleFlux. 2 replies.
Sort Posts: Previous Next
  •  06-27-2008, 9:25 AM 10030

    Problem binding to query when joined field is null

    I am using ES 2007.1.1210 and MyGeneration 1.2.0.7.

    Let's say I have two tables, Employee and JobTitle.
    Employee has columns PKEmployeeID, Name, and FKJobTitleID. FKJobTitleID is nullable.
    JobTitle has columsn PKJobTitleID, Name.
    There is a relationship between the two table via the JobTitleID fields.

    I am binding a DetailsView at runtime to a query with the following code:

     

    Code:
    EmployeeCollection emps = new EmployeeCollection();
    EmployeeQuery eq = new EmployeeQuery("eq");
    JobTitleQuery jq = new JobTitleQuery("jq");
    
    eq.Select(eq.PKEmployeeID, eq.Name, jq.Name.As("JobName"));
    eq.LeftJoin(jq).On(eq.FKJobTitleID == jq.PKJobTitleID);
    eq.Where(eq.PKEmployeeID == 42);
    if (emps.Load(eq))
    {
    DetailsView1.DataSource = emps.LowLevelBind();
    DetailsView1.DataBind();
    }
     

    This works if Employee.FKJobTitleID is not null but not when it is null.
    The problem is that there is no property made for JobName when FKJobTitleID is null, though the SQL does return a null value for it.

  •  06-27-2008, 10:39 AM 10032 in reply to 10030

    Re: Problem binding to query when joined field is null

    I can't recall of the top of my head or not if Coalesce is supported in ES2007 but I know it is in ES2008. I think it is in ES2007 also. Then you could do this:

    Code:
    MyCollection coll = new MyCollection();
    coll.Query.Select(coll.Query.LastName.Coalesce("'Smith'").As("MyColumn));
    coll.Query.Load();
    

    or in  your case ...

    jq.Name.Coalesce('""').As("JobName"));

    and it might do the trick?

     


    EntitySpaces | Twitter | BLOG | Please honor our Software License
  •  06-30-2008, 8:40 AM 10065 in reply to 10032

    Re: Problem binding to query when joined field is null

    Thank you, Coalesce works great and is in ES2007. I'll have to remember that this support exists, because it can be useful to return "<N/A>" etc. instead of null sometimes.

     For anyone trying to copy and paste the second statement Mike wrote, it's actually:

     

    Code:
    jq.Name.Coalesce("''").As("JobName");

     Just a switch of the double quotes and single quotes was all.

     

    Thanks again!

View as RSS news feed in XML