none
using UDF's to load related entities RRS feed

  • Question

  • I'm have a situation where I'm required to use UDF's for all database access. I have created a udf for an entity and have it working:

    MyDataContext context = new MyDataContext(server, database);
    IQueryable<Customer> custs = from c in context.GetCustomer();

    Now I need to load a related entity (CustomerType). I specified this via the DataLoadOptions class; but l can't seem to figure out how to get LTS to use my UDF instead of joining the related table directly.

    MyDataContext context = new MyDataContext(server, database);

    var options = new DataLoadOptions();
    options.LoadWith<Customer>(c => c.CustomerType);

    context.LoadOptions = options;

    var custs = from c in context.GetCustomer().ToList<Customer>();


    I tried using a join like this:

        var foo = from c in context.GetCustomer(null)
                              join ct in context.GetCustomerType()
                              on  c.CustmerTypeId equals ct.Id
                              select c;

    but it did not populate the Related Entity

    Is it possible to use User Defined Functions to load related entites without using deffered loading?
    Saturday, October 11, 2008 12:26 AM

All replies

  •  I came up with this workaround:

            var dtoList = from c in context.GetCustomer(null)
                                  join ct in context.GetCustomerType()
                                  on c.CustomerTypeId equals ct.Id
                                  select new {c, ct };

    Then I iterate through the anonymous list and manually assign the customer type to each customer:

         foreach(var dto in dtoList)
                    {
                        dto.dm.DiagnosisType = dto.dt;
                        masters.Add(dto.dm);
                    }


    Some of the Properties in the Customer objects setters are marker protected, so I needed to use the anonymous type as a sort of dto.

    This seems like it could potentially have some performance issues with larger sets of data.


    Still looking for suggestions for a cleaner solution.
                   
    Monday, October 13, 2008 4:29 PM