3

クエリ式を使用して、この基本的な SQL ステートメントを生成しようとしています。

SELECT *
FROM contact
INNER JOIN businessunit on contact.businessunitid = businessunit.businessunitid
INNER JOIN new_example on businessunit.new_exampleid = new_example.new_exampleid

このクエリ式テストの使用:

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"

修正は AddLink メソッドを使用せず、LinkFromEntityName を指定する LinkEntity を作成することですが、これをバグと考えるのは間違っていますか?

4

1 に答える 1

1

リンクがクエリ式内に正しく追加されるように、この問題を正しく処理するオーバーロードされた汎用AddChildLinkメソッドを作成しました。また、いくつかのパラメーターをデフォルトにするいくつかのオーバーロードを追加しました。

/// <summary>
/// Created do to possible bug (http://stackoverflow.com/questions/10722307/why-does-linkentity-addlink-initialize-the-linkfromentityname-with-its-own-lin)
/// Adds the new LinkEntity as a child to this LinkEnity, rather than this LinkEntity's LinkFrom Entity
/// Assumes that the linkFromAttributeName and the linkToAttributeName are the same
/// </summary>
/// <param name="link"></param>
/// <param name="linkToEntityName"></param>
/// <param name="linkAttributesName"></param>
/// <returns></returns>
public static LinkEntity AddChildLink(this LinkEntity link, string linkToEntityName, string linkAttributesName)
{
    return link.AddChildLink(linkToEntityName, linkAttributesName, linkAttributesName);
}

/// <summary>
/// Created do to possible bug (http://stackoverflow.com/questions/10722307/why-does-linkentity-addlink-initialize-the-linkfromentityname-with-its-own-lin)
/// Adds the new LinkEntity as a child to this LinkEnity, rather than this LinkEntity's LinkFrom Entity
/// Assumes that the linkFromAttributeName and the linkToAttributeName are the same
/// </summary>
/// <param name="link"></param>
/// <param name="linkToEntityName"></param>
/// <param name="linkAttributesName"></param>
/// <param name="joinType"></param>
/// <returns></returns>
public static LinkEntity AddChildLink(this LinkEntity link, string linkToEntityName, string linkAttributesName, JoinOperator joinType)
{
    return link.AddChildLink(linkToEntityName, linkAttributesName, linkAttributesName, joinType);
}

/// <summary>
/// Created do to possible bug (http://stackoverflow.com/questions/10722307/why-does-linkentity-addlink-initialize-the-linkfromentityname-with-its-own-lin)
/// Adds the new LinkEntity as a child to this LinkEnity, rather than this LinkEntity's LinkFrom Entity
/// </summary>
/// <param name="link"></param>
/// <param name="linkToEntityName"></param>
/// <param name="linkFromAttributeName"></param>
/// <param name="linkToAttributeName"></param>
/// <returns></returns>
public static LinkEntity AddChildLink(this LinkEntity link, string linkToEntityName,
    string linkFromAttributeName, string linkToAttributeName)
{
    return link.AddChildLink(linkToEntityName, linkFromAttributeName, linkToAttributeName, JoinOperator.Inner);
}

/// <summary>
/// Created do to possible bug (http://stackoverflow.com/questions/10722307/why-does-linkentity-addlink-initialize-the-linkfromentityname-with-its-own-lin)
/// Adds the new LinkEntity as a child to this LinkEnity, rather than this LinkEntity's LinkFrom Entity
/// </summary>
/// <param name="link"></param>
/// <param name="linkToEntityName"></param>
/// <param name="linkFromAttributeName"></param>
/// <param name="linkToAttributeName"></param>
/// <returns></returns>
public static LinkEntity AddChildLink(this LinkEntity link, string linkToEntityName,
    string linkFromAttributeName, string linkToAttributeName, JoinOperator joinType)
{
    var child = new LinkEntity(
        link.LinkToEntityName, linkToEntityName,
        linkFromAttributeName, linkToAttributeName, joinType);
    link.LinkEntities.Add(child);
    return child;
}

public static LinkEntity AddLink(this QueryExpression qe, string linkToEntityName, string linkAttributesName)
{
    return qe.AddLink(linkToEntityName, linkAttributesName, linkAttributesName);
}

public static LinkEntity AddLink(this QueryExpression qe, string linkToEntityName, string linkAttributesName, JoinOperator joinType)
{
    return qe.AddLink(linkToEntityName, linkAttributesName, linkAttributesName, joinType);
}

これにより、メソッドが短縮され、連鎖が可能になります。

var qe = new QueryExpression("new_entitya");
qe.AddLink("new_entityb", "new_entitybid").
    AddChildLink("new_entityc", "new_entitybid").
    LinkCriteria.AddCondition("new_entitycid", ConditionOperator.Equal, id);
于 2012-07-12T03:30:22.103 に答える