I’m trying to generate this basic SQL statement using Query Expressions:
SELECT *
FROM contact
INNER JOIN businessunit on contact.businessunitid = businessunit.businessunitid
INNER JOIN new_example on businessunit.new_exampleid = new_example.new_exampleid
Using this Query Expression Test:
var query = new QueryExpression("contact");
var bu = query.AddLink("businessunit", "businessunitid", "businessunitid");
var buChildLink = bu.AddLink("new_example", "new_exampleid", "new_exampleid");
Assert.AreEqual("businessunit", buChildLink.LinkFromEntityName); // Fails. Actual value is "contact"
The fix is to not use the AddLink method, but create the LinkEntity where you specify the LinkFromEntityName, but am I wrong in thinking this is a bug?
I’ve created an overloaded generic AddChildLink method that correctly handles this issue so that the link gets added correctly within the query expression. I’ve also added some overloads that default some of the parameters.
This shortens method and allows for chaining: