Here is short example of how to execute a method on an entity Programmatically. Assuming you already have a External content type “My External content type” setup to a Sql database lets look at a console application
private static void ExecuteMethod()
{
Console.WriteLine(“\nNow Executing methods”);
using (SPSite site = newSPSite(siteUrl))
{
using (newSPServiceContextScope( SPServiceContext.GetContext( site)))
{
BdcService service = SPFarm.Local.Services. GetValue();
IMetadataCatalog catalog = service. GetDatabaseBackedMetadataCatal og(SPServiceContext.Current);
IEntity entity = catalog.GetEntity(siteUrl, “My External content type”);
ILobSystemInstance LobSysteminstance = entity.GetLobSystem(). GetLobSystemInstances()[0]. Value;
IMethodInstance method = entity.GetMethodInstance(“Read List”, MethodInstanceType.Finder);
IEntityInstanceEnumerator handle = entity.FindFiltered(method. GetFilters(), LobSysteminstance);
Console.WriteLine(“Title in My External content type:”);
while (handle.MoveNext())
{
Console.WriteLine(handle. Current["Title"].ToString());
}
}}}
private static void ExecuteMethod()
{
Console.WriteLine(“\nNow Executing methods”);
using (SPSite site = newSPSite(siteUrl))
{
using (newSPServiceContextScope(
{
BdcService service = SPFarm.Local.Services.
IMetadataCatalog catalog = service.
IEntity entity = catalog.GetEntity(siteUrl, “My External content type”);
ILobSystemInstance LobSysteminstance = entity.GetLobSystem().
IMethodInstance method = entity.GetMethodInstance(“Read List”, MethodInstanceType.Finder);
IEntityInstanceEnumerator handle = entity.FindFiltered(method.
Console.WriteLine(“Title in My External content type:”);
while (handle.MoveNext())
{
Console.WriteLine(handle.
}
}}}
No comments:
Post a Comment