Following the source code found here: http://code.msdn.microsoft.com/office/Creating-SharePoint-2010-ad694d17
I've managed to create the Create, Update and Delete method, but only the Delete operation works in the external list.
Here is the code snippet:
// create the delete method
Method getDeleteMethod = customerEntity.Methods.Create("DeleteCustomer", true, false, "DeleteCustomer");
// specify the query and command type
getDeleteMethod.Properties.Add("RdbCommandText", "DELETE FROM [tblCustomer] where [Customer ID] = @CustomerID");
getDeleteMethod.Properties.Add("RdbCommandType", "Text");
// create the Customer return parameter
Parameter DeleteIDParameter = getDeleteMethod.Parameters.Create("@CustomerID", true, DirectionType.In);
// create the TypeDescriptor for the CustomerID parameter
DeleteIDParameter.CreateRootTypeDescriptor(new TypeDescriptorParams(standardStringType)
{
Name = "CustomerID",
IdentifierReference = customerIdentifierRef,
MetadataCatalog = catalog
});
getDeleteMethod.MethodInstances.Create(getDeleteMethod.Name, true, null,
MethodInstanceType.Deleter, true);
//end delete
//update method
// create the update method
Method getUpdateMethod = customerEntity.Methods.Create("UpdateCustomer", true, false, "UpdateCustomer");
// specify the query and command type
getUpdateMethod.Properties.Add("RdbCommandText", "UPDATE [tblCustomer] SET [Company Name] = @CompanyName WHERE [Customer ID] = @CustomerID");
getUpdateMethod.Properties.Add("RdbCommandType", "Text");
// create the Customer return parameter
Parameter UpdateIDParameter = getUpdateMethod.Parameters.Create("@CustomerID", true, DirectionType.In);
Parameter UpdateIDParameter2 = getUpdateMethod.Parameters.Create("@CompanyName", true, DirectionType.In);
// create the TypeDescriptor for the CustomerID parameter
//IEntityReference coyname = customerEntityRef;
UpdateIDParameter.CreateRootTypeDescriptor(new TypeDescriptorParams(standardStringType)
{
Name = "CustomerID",
IdentifierReference = customerIdentifierRef,
MetadataCatalog = catalog
});
UpdateIDParameter2.CreateRootTypeDescriptor(new TypeDescriptorParams(standardStringType)
{
Name = "CompanyName"
});
getUpdateMethod.MethodInstances.Create(getUpdateMethod.Name, true, null,
MethodInstanceType.Updater, true);
//end update
//insert method
// create the insert method
Method getInsertMethod = customerEntity.Methods.Create("InsertCustomer", true, false, "InsertCustomer");
// specify the query and command type
getInsertMethod.Properties.Add("RdbCommandText", "INSERT INTO [tblCustomer] ([Customer ID], [Company Name]) VALUES (@CustomerID, @CompanyName)");
getInsertMethod.Properties.Add("RdbCommandType", "Text");
// create the Customer return parameter
Parameter InsertIDParameter = getInsertMethod.Parameters.Create("@CustomerID", true, DirectionType.In);
Parameter InsertIDParameter2 = getInsertMethod.Parameters.Create("@CompanyName", true, DirectionType.In);
// create the TypeDescriptor for the CustomerID parameter
InsertIDParameter.CreateRootTypeDescriptor(new TypeDescriptorParams(standardStringType)
{
Name = "CustomerID",
IdentifierReference = customerIdentifierRef,
MetadataCatalog = catalog
});
InsertIDParameter2.CreateRootTypeDescriptor(new TypeDescriptorParams(standardStringType)
{
Name = "CompanyName",
MetadataCatalog = catalog
});
// create the Customer return parameter
Parameter insertParameter = getInsertMethod.Parameters.Create("tblCustomer", true, DirectionType.Return);
TypeDescriptorParams returnElementTypeInsertDescriptorParams =
new TypeDescriptorParams
{
Name = "tblCustomer",
IsCached = true,
Type = typeof(IDbTransaction),
Flags = TypeDescriptorFlags.None,
};
TypeDescriptorParams returnCollectionTypeInsertDescriptorParams =
new TypeDescriptorParams(returnElementTypeInsertDescriptorParams)
{
Type = typeof(IDataRecord),
Flags = TypeDescriptorFlags.IsCollection,
MetadataCatalog = catalog
};
// create the TypeDescriptors for the Customer return parameter
TypeDescriptor returInsertTypeDescriptor =
insertParameter.CreateRootTypeDescriptor(returnCollectionTypeInsertDescriptorParams);
TypeDescriptor returnElementInsertTypeDescriptor =
returInsertTypeDescriptor.CreateChildTypeDescriptor(returnElementTypeInsertDescriptorParams);
//returnElementInsertTypeDescriptor.Delete();
returnElementInsertTypeDescriptor.CreateChildTypeDescriptor(new TypeDescriptorParams(standardStringType)
{
Name = "Customer ID",
IdentifierReference = customerIdentifierRef,
});
returnElementInsertTypeDescriptor.CreateChildTypeDescriptor(new TypeDescriptorParams(standardStringType)
{
Name = "Company Name"
});
getInsertMethod.MethodInstances.Create(getInsertMethod.Name, true, returnElementInsertTypeDescriptor,
MethodInstanceType.Creator, true);
//end insert
I can't find any examples similar to this approach that I'am using. I would gladly appreciate any input if anyone knows how to do the Update and Create method!? Thanks