An external list is one of the most-asked for features in SharePoint 2010 from developers. It allows users to expose data as a SharePoint list from common data sources such as a relational database or web services. Once the external list is created, developers can access the data via the list API that they are familiar with.

I wanted to create the external list from an external content type programatically in a feature receiver on activate. Nothing is out there from Google nor Bing about how to do this. I found that there is a new overloaded method to create the list on the SPListCollection class that takes an instance of SPListDataSource. SPListDataSource contains the information about how to get data from BCS. If you have created a BCS  model or external content type using SharePoint Designer, then you will know all the values required to create an instance of SPListDataSource that works with your BCS model.

Here is what I used to create mine (you need to know the values for the LobSystemInstance, EntityNamespace, Entity and SpecificFinder):

SPListDataSource ds = new SPListDataSource();
ds.SetProperty(SPListDataSource.BDCProperties.LobSystemInstance, "RinkNet");
ds.SetProperty(SPListDataSource.BDCProperties.EntityNamespace, "RinkNet.CurrentPlayers");
ds.SetProperty(SPListDataSource.BDCProperties.Entity, "CurrentPlayers");
ds.SetProperty(SPListDataSource.BDCProperties.SpecificFinder, "CurrentPlayersRead Item");

using (SPSite site = new SPSite("http://localhost"))
  using (SPWeb web = site.RootWeb)
    web.Lists.Add("CurrentPlayers", "", "Lists/CurrentPlayers", ds);