1

Hi I have created BCS model which use secure store service for authentication to External system.Everything works fine using out of box external list and BCS web parts.

But I want to create custom web part, so I need to call finder method in web part programmatically. In BCS I have finder method with three parameters username,password and current User.

How can I call finder method programmatically with these 3 parameters?

Please advise.

Thanks

Ronak

1 Answer 1

2
//Connect to the BDC Service Application proxy
BdcService service = SPFarm.Local.Services.GetValue<BdcService>();
if (service == null)
    throw new Exception("No BDC Service Application found.");

//Connect to metadata catalog
DatabaseBackedMetadataCatalog catalog = service.GetDatabaseBackedMetadataCatalog(SPServiceContext.GetContext(site));

//Get entity
IEntity ect = catalog.GetEntity(entityNamespace, entityName);

//Get LobSystem
ILobSystem lob = ect.GetLobSystem();

//Get LobSystemInstance
ILobSystemInstance lobi = lob.GetLobSystemInstances()[lobSystemInstance];

//Get Method Instance
IMethodInstance mi = ect.GetMethodInstance(specificFinderMethodInstance, MethodInstanceType.SpecificFinder);

//Get Parameters
IParameterCollection parameters = mi.GetMethod().GetParameters();

//Set Parameters
object[] arguments = new object[parameters.Count];
arguments[0] = entityInstanceIdentifier;

//Execute
ect.Execute(mi, lobi, ref arguments);

//Display
PropertyInfo[] props = arguments[1].GetType().GetProperties();
PropertyInfo prop = props[0];
SqlDataReader reader = (SqlDataReader)(prop.GetValue(arguments[1], null));
if (reader.HasRows)
{
    while (reader.Read())
    {
        Console.WriteLine(reader.GetString(3) + " " + reader.GetString(5));
    }
}

Source: TechNet: Call custom BCS methods from a webpart

1
  • Thanks Kevin for your reply and code.i do have this code from Scott book and i have used this code to call Finder Method in webparts and it worked.Now i have IEnumerable Items of some entity lets say Workspace now i want to get datatable or collection of objects how can i do that.
    – Ronak
    Jul 9, 2012 at 14:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.