本文整理汇总了C#中ObjectContext.ExecuteStoreQuery方法的典型用法代码示例。如果您正苦于以下问题:C# ObjectContext.ExecuteStoreQuery方法的具体用法?C# ObjectContext.ExecuteStoreQuery怎么用?C# ObjectContext.ExecuteStoreQuery使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ObjectContext
的用法示例。
在下文中一共展示了ObjectContext.ExecuteStoreQuery方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PublishOrgUnitEntityAssociations
/// <summary>
/// Publishes the org unit entity associations. This data tracks which org units are directly
/// associated with an entity (provider, event, etc.) as well as the parents of those org units.
/// This facilitates rapid filtering of entities based on their position in the org unit hierarchy.
/// </summary>
/// <param name="objectContext">The object context.</param>
public static void PublishOrgUnitEntityAssociations(ObjectContext objectContext)
{
// Remove all existing org unit entity association data
const string sqlDeleteText = @"DELETE FROM OrgUnitEntityAssociations;";
objectContext.ExecuteStoreQuery<object>(sqlDeleteText);
// Read all registered org unit entity types
var orgUnitEntityTypeObjectSet = objectContext.CreateObjectSet<OrgUnitEntityType>();
var entityTypes = (from t in orgUnitEntityTypeObjectSet select t).ToArray();
// Generate org unit entity association data for each entity type
foreach (OrgUnitEntityType entityType in entityTypes)
{
// Build Dynamic SQL INSERT statement for current entity type
//{0} = AssociationTableName
//{1} = EntityIdFieldName
//{2} = OrgUnitIdFieldName
//{3} = OrgUnitEntityTypeId
const string sqlInsertTemplate =
@"INSERT INTO OrgUnitEntityAssociations
SELECT OrgUnitEntityTypeId, EntityId,
CASE WHEN (DirectOrgUnits LIKE '%,-') THEN LEFT(DirectOrgUnits, LEN(DirectOrgUnits) - 2) ELSE DirectOrgUnits END DirectOrgUnits,
CASE WHEN (DirectAndParentOrgUnits LIKE '%,-') THEN LEFT(DirectAndParentOrgUnits, LEN(DirectAndParentOrgUnits) - 2) ELSE DirectAndParentOrgUnits END DirectAndParentOrgUnits,
CASE WHEN (DirectAndLinkedOrgUnits LIKE '%,-') THEN LEFT(DirectAndLinkedOrgUnits, LEN(DirectAndLinkedOrgUnits) - 2) ELSE DirectAndLinkedOrgUnits END DirectAndLinkedOrgUnits,
CASE WHEN (DirectAndParentAndLinkedOrgUnits LIKE '%,-') THEN LEFT(DirectAndParentAndLinkedOrgUnits, LEN(DirectAndParentAndLinkedOrgUnits) - 2) ELSE DirectAndParentAndLinkedOrgUnits END DirectAndParentAndLinkedOrgUnits
FROM
(
SELECT
{3} AS OrgUnitEntityTypeId,
EntityId,
'-' + OrgUnitDirectList AS DirectOrgUnits,
'-' + OrgUnitDirectList + ISNULL(OrgUnitParentList, '') AS DirectAndParentOrgUnits,
'-' + OrgUnitDirectList + ISNULL(OrgUnitLinkedList, '') AS DirectAndLinkedOrgUnits,
'-' + OrgUnitDirectList + ISNULL(OrgUnitParentList, '') + ISNULL(OrgUnitLinkedList, '') AS DirectAndParentAndLinkedOrgUnits
FROM
(
SELECT EntityId,
(
SELECT DISTINCT Cast(eou.{2} as varchar) + '-,-' AS [text()]
FROM {0} eou WHERE eou.{1} = entity.EntityId FOR XML PATH('')
) AS OrgUnitDirectList,
(
SELECT DISTINCT Cast(ouap.PrimaryId as varchar) + '-,-' AS [text()]
FROM OrgUnitAssociationsPublished ouap
INNER JOIN {0} eou ON eou.{2} = ouap.SecondaryId
WHERE eou.{1} = entity.EntityId and Direction = 'Forward'
FOR XML PATH('')
) AS OrgUnitParentList,
(
SELECT DISTINCT Cast(oup.LinkedOrgUnitId as varchar) + '-,-' AS [text()]
FROM OrgUnitsPublished oup
INNER JOIN {0} eou ON eou.{2} = oup.Id
AND eou.{1} = entity.EntityId FOR XML PATH('')
) AS OrgUnitLinkedList
FROM
(
SELECT DISTINCT {1} AS EntityId FROM {0}
) entity
) OrgUnits
WHERE (OrgUnitDirectList IS NOT NULL)
) OrgUnitsAppended";
string sqlInsertText = string.Format(CultureInfo.InvariantCulture, sqlInsertTemplate, entityType.AssociationTableName, entityType.EntityIdFieldName, entityType.OrgUnitIdFieldName, entityType.Id);
objectContext.ExecuteStoreQuery<object>(sqlInsertText);
}
}