is it possible to define an external contentType in code?
As an alternative: Is it possible to deploy an bdc-model using code (i.e. create the xml "on the fly" then deploy that using code)?


For sure it is. Visual Studio 2010 has even a project item template for it. Have a look here http://troyscott.ca/2010/08/07/bdc-models-in-visual-studio-2010-for-sharepoint-foundation-server-2010/ for something to get you started.

The ECT gets created automatically by your BDC model upon solution deployment.

  • 1
    but when that is said, it is MUCH easier to get the foundation for the code by using SharePoint Designer :-) (and that is just about the only thing that tool is useful for) – Anders Rask Jun 4 '12 at 9:45
  • Thanks for the info, but is is possible to do this "in code"? I.e. not in a Solution/WSP? Or better can I do var bdcm = this.CreateBdcm(); this.InstallToFarm(bdcm);? – Nils Jun 4 '12 at 9:50
  • what do you mean by "in code" this case, ECMA Javascript? - if your BDC model doesn't exist already on the farm, i don't see it as an easy task. You could create/deploy the model even via SPD (the easy way and no-code solution) and probably with a little effort you could create an instance of the ECT via ECMA script. Otherwise, the best way would be to deploy your model via .WSP – Marius Constantinescu - MVP Jun 4 '12 at 10:00
  • with "in code" I mean using c# and sharepoint object model. – Nils Jun 4 '12 at 10:49
  • You could use this msdn.microsoft.com/en-us/library/ff798311.aspx to create/export your BDC and then use either the UI, or PowerShell (e.g. c-sharpcorner.com/uploadfile/anavijai/…) or sharemuch.com/2010/02/02/…. Haven't tried by code but a similar as the Powershell should do it. – Marius Constantinescu - MVP Jun 4 '12 at 20:30

For completeness:

I found what I was looking for in the MSDN-Article "Code Snippet: Create an External Content Type Using the Administration Object Model".

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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