Code First support in DevForce is provided through a NuGet package. Here we provide information on how to install the DevForce Code First NuGet package.
DevForce Code First support is distributed through NuGet.
To install the DevForce 2010 Code First NuGet package in one or more projects within a solution, right-click on the Solution or an individual project, select "Manage NuGet Packages..." and enter a search term, such as "IdeaBlade.DevForce-2010".
If you see a Code First package from both DevForce 2010 and DevForce 2012, be sure to pick the DevForce 2010 package. The package id is IdeaBlade.DevForce-2010.Aop.
The package installs necessary DevForce files and assemblies, as well as PostSharp and EntityFramework dependencies. This package requires that DevForce 2010 is already installed, and can be installed to Silverlight 4, Silverlight 5, and .NET 4.0 projects.
Both the DevForce and PostSharp packages modify the MSBuild targets for the projects they are installed to. If you peek into the project file you'll see additional imports. For example, a C# project might look something like this:
XML | <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <Import Project="..\packages\PostSharp.2.1.7.22\tools\PostSharp.targets" Condition="Exists('..\packages\PostSharp.2.1.7.22\tools\PostSharp.targets')" /> <Import Project="..\packages\IdeaBlade.DevForce-2010.Aop.6.1.9\tools\IdeaBlade.DevForce.Common.targets" Condition="Exists('..\packages\IdeaBlade.DevForce-2010.Aop.6.1.9\tools\IdeaBlade.DevForce.Common.targets')" /> |
The PostSharp targets file ensures that your Code First entities are re-written, while the DevForce targets will fire the EntityModelMetadataDeploy task which builds the metadata file for your model.
You should install the DevForce Code First NuGet package to the project which will hold your code first model. If you are working in Silverlight, you should also install the package to your "linked" Silverlight project. In general, the package should be installed to any project which will contain an *ibmmx metadata file.
You should also install the DevForce Code First NuGet package to any project defining a base class to ensure that the correct assembly references are added and PostSharp MSBuild support is enabled. If your base class uses the ProvideEntityAspect or ProvideComplextAspect aspects, then the assembly must be "enhanced" by PostSharp and requires that the MSBuild targets in the project file are modified.
If you have an existing Code First project created with an earlier version of DevForce (prior to 6.1.9), you'll need to do the following:
The package will not update an existing EntityFramework package, and can be used with EF versions 4.1 and above.
The version of the DevForce 2010 Code First NuGet package must match the version of DevForce you have installed. After upgrading from an earlier DevForce version, always be sure to also upgrade to the corresponding version of the NuGet package. You can easily do this using the "Manage NuGet Packages" wizard to look for updates:
Alternately, if you prefer to stay at an earlier DevForce version, you'll need to make sure that you specify the version when retrieving the NuGet package. For example, use the Package Manager console to install the 6.1.9 package:
The DevForce Code First NuGet package supports any version of the EntityFramework NuGet package between 4.1 and 5.x. If you install the Code First package to a project for which EF is already installed, the Code First package will not update it.
However, if you install the Code First package to a project which does not already contain the EntityFramework package, EntityFramework 4.1 is installed. This occurs because the DevForce package allows a range of versions, and NuGet will install the earliest version if the package is not already present.
You can separately update the EntityFramework package to your desired version by using the Package Manager wizard or console.
DevForce 2010 does not support EF 6.