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.
I found what I was looking for in the MSDN-Article "Code Snippet: Create an External Content Type Using the Administration Object Model".