Author |
Share Topic Topic Search Topic Options
|
murray.bryant
Groupie
Joined: 11-Jan-2012
Location: Australia
Posts: 44
|
Post Options
Quote Reply
Topic: Code Second Migration Issues Posted: 05-Feb-2013 at 11:31pm |
Hi
I am trying to migrate an existing project across to code-first.
I have followed the steps from the documentation
- Change Template to CodeFirst and Save - Add nuget code-first package - Create new Model.cs file copy pocos to file - Delete old EDMX - Change Connection String
When I then build the project nothing happens. No ibmmx is generated
in the output
>------ Build started: Project: Torpedo.Geo.Model, Configuration: Debug Any CPU ------ 1>Build started 6/02/2013 3:30:06 PM. 1>RestorePackages: 1> "C:\Development\Torpedo.Geo\.nuget\nuget.exe" install "C:\Development\Torpedo.Geo\Torpedo.Geo.Model\packages.config" -source "" -RequireConsent -solutionDir "C:\Development\Torpedo.Geo\ " 1> All packages listed in packages.config are already installed. 1>PostSharp21InspectReferences: 1> Detected reference to 'PostSharp'. 1>GenerateTargetFrameworkMonikerAttribute: 1>Skipping target "GenerateTargetFrameworkMonikerAttribute" because all output files are up-to-date with respect to the input files. 1>CoreCompile:
I can't see devforce trying to generate the metadata
I am kind of stuck here. Any suggestions would be appreciated
thanks Murray
Edited by murray.bryant - 05-Feb-2013 at 11:31pm
|
|
kimj
IdeaBlade
Joined: 09-May-2007
Posts: 1391
|
Post Options
Quote Reply
Posted: 06-Feb-2013 at 9:48am |
Make sure that it was the DevForce 2012 Code First NuGet package that you installed - we also have a similar package for DF2010. You can also check that the package installed correctly by looking at the project file contents. Here's a link showing what to look for: http://drc.ideablade.com/devforce-2012/bin/view/Documentation/code-first-entity-classes#HInstallDevForceCodeFirstsupport If the package is installed but the problem persists, turn up the verbosity of the MSBuild output to "normal" or higher (via the VS Tools menu) to see if anything shows up during the build.
|
|
murray.bryant
Groupie
Joined: 11-Jan-2012
Location: Australia
Posts: 44
|
Post Options
Quote Reply
Posted: 06-Feb-2013 at 3:33pm |
Yes it is 2012 that is installed
the project seems to be installed
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <Import Project="$(SolutionDir)\.nuget\nuget.targets" /> <Import Project="..\packages\PostSharp.2.1.7.28\tools\PostSharp.targets" Condition="Exists('..\packages\PostSharp.2.1.7.28\tools\PostSharp.targets')" /> <Import Project="..\packages\IdeaBlade.DevForce.Aop.7.0.3\tools\IdeaBlade.DevForce.Common.targets" Condition="Exists('..\packages\IdeaBlade.DevForce.Aop.7.0.3\tools\IdeaBlade.DevForce.Common.targets')" />
I already posted the result from the normal msbuild. Looking through the verbose setting is hard to spot anything. Can you post what should be showing in the build. Or something I can search for in the output.
thanks Murray
|
|
kimj
IdeaBlade
Joined: 09-May-2007
Posts: 1391
|
Post Options
Quote Reply
Posted: 06-Feb-2013 at 4:08pm |
The "EntityModelMetadataDeploy" task should be showing up in the MSBuild output, but then it will also raise build warnings and errors when it encounters problems, and these would be hard to miss. Do you also have DF2010 installed? If so, double check that all IdeaBlade assembly references are pointing to version 7.0.3. If you have a version of DF2010 prior to 6.1.9 that will cause problems too, as side-by-side installations of both products are only supported with 6.1.9 and above.
|
|
murray.bryant
Groupie
Joined: 11-Jan-2012
Location: Australia
Posts: 44
|
Post Options
Quote Reply
Posted: 06-Feb-2013 at 4:15pm |
I uninstalled all of my devforce 2010 a while back
In the detailed log for the model project build there is no mention of EntityModelMetadataDeploy
what could be causing this?
Edited by murray.bryant - 06-Feb-2013 at 4:24pm
|
|
murray.bryant
Groupie
Joined: 11-Jan-2012
Location: Australia
Posts: 44
|
Post Options
Quote Reply
Posted: 06-Feb-2013 at 4:25pm |
And yes all my references are Ideablade 7.0.3
|
|
kimj
IdeaBlade
Joined: 09-May-2007
Posts: 1391
|
Post Options
Quote Reply
Posted: 06-Feb-2013 at 5:02pm |
We've seen some issues with the DevForce 2010 uninstall not cleanly removing MSBuild targets. Check your \program files (x86)\MSBuild\v4.0 folder for an IdeaBlade.*.targets file and remove it if found. There might also be an IdeaBlade folder under the MSBuild folder, and that can be removed too. If that's not causing the problem, can you zip up the project in question and either upload here or send to our IdeaBladeSupportTrack email address?
|
|
murray.bryant
Groupie
Joined: 11-Jan-2012
Location: Australia
Posts: 44
|
Post Options
Quote Reply
Posted: 06-Feb-2013 at 5:16pm |
I have zipped and sent through to IdeabladeSupportTrack
There were no Ideablade* files in teh MSBuild directories
|
|
kimj
IdeaBlade
Joined: 09-May-2007
Posts: 1391
|
Post Options
Quote Reply
Posted: 06-Feb-2013 at 7:17pm |
Does this project actually build successfully? The ibmmx metadata file is only created if the assembly can be built without errors, as the EntityModelMetadataDeploy task kicks in after a successful compilation. I notice that the ProvideEntityAspect attribute is specified on both the base and derived classes, which is one problem. There are also some constructs in use, such as PathFor and PropertyMetadata, which aren't defined for Code First entities. Once you fix the build problems the metadata files should generate.
|
|
murray.bryant
Groupie
Joined: 11-Jan-2012
Location: Australia
Posts: 44
|
Post Options
Quote Reply
Posted: 06-Feb-2013 at 8:19pm |
The project worked fine when using the EDM
As you say what I seem to be running into is the functionality that is not present in code-first that is there for the edm use.
It would be nice if these differences were documented somewhere. Do you know where such a resource is?
I will work through the rest of the build errors. I guess I was hoping some of these would disappear once the ibmmx process occurred. But it seems that was wrong.
|
|
murray.bryant
Groupie
Joined: 11-Jan-2012
Location: Australia
Posts: 44
|
Post Options
Quote Reply
Posted: 06-Feb-2013 at 9:31pm |
Originally posted by kimj
There are also some constructs in use, such as PathFor and PropertyMetadata, which aren't defined for Code First entities.
|
These are both generated by devforce in the EDM version. Do you have any code that I could add to a base class that replicates this functionality?
PropertyMetadata and pathfor I use extensively for verifiers. ( as per your documenation)
Edited by murray.bryant - 06-Feb-2013 at 9:41pm
|
|
kimj
IdeaBlade
Joined: 09-May-2007
Posts: 1391
|
Post Options
Quote Reply
Posted: 07-Feb-2013 at 11:20am |
Sorry, we don't currently have any documentation describing how to move an EDMX-based model to Code First. In the EDMX-generated code, you'll see the PathFor method generated for every entity class like so: public static string PathFor(System.Linq.Expressions.Expression<System.Func<Employee, object>> expr) { return IbCore.PropertyPath.For<Employee>(expr); } You have several options for how you handle this: one would be to directly call the IdeaBlade.Core.PropertyPath method instead of using PathFor; another would be to include this helper method in your entity class definitions; and another might be to include this in a base or helper class as a generic method: public static string PathFor<T>(System.Linq.Expressions.Expression<System.Func<T, object>> expr) { return PropertyPath.For<T>(expr); } The PropertyMetadata is a bit different. In EDMX-based models PropertyMetadata is a nested class within each entity holding the static data property definitions for the entity. In a Code First model, all metadata is dynamically loaded from the ibmmx file, and is available in the EntityMetadataStore. So again you should decide how best to architect this in your solution. You can access metadata for an entity like so: public static EntityMetadata PropertyMetadata { get { return EntityMetadataStore.Instance.GetEntityMetadata(typeof(Employee)); } } Entity properties are available from the EntityMetadata in several ways, for example: Employee.PropertyMetadata.EntityProperties Employee.PropertyMetadata.DataProperties Employee.PropertyMetadata.NavigationProperties ... and others So you might have a simple helper method like the following: public static EntityProperty GetPropertyMetadata(string prop) { return PropertyMetadata.EntityProperties[prop]; }
|
|
murray.bryant
Groupie
Joined: 11-Jan-2012
Location: Australia
Posts: 44
|
Post Options
Quote Reply
Posted: 07-Feb-2013 at 5:09pm |
Thanks for the reply
I am still struggling with this. I am trying to implement a cross type verifier.
<quote> private static Verifier GetOrderDateAfterHiredVerifier() {
string description = "OrderDate must be after the sales rep's HireDate."; DelegateVerifier<Order> v = new DelegateVerifier<Order>( description, OrderDateAfterHiredCondition);
v.VerifierOptions.ExecutionModes = VerifierExecutionModes.InstanceAndOnAfterSetTriggers;
v.AddTrigger(Order.PathFor(o => o.OrderDate)); v.AddTrigger(new TriggerLink(new TriggerItem (typeof(Employee), Employee.PathFor(e => e.HireDate)), e => ((Employee)e).Orders, // Path from trigger (Employee) to Order true)); // True = that path returns multiple orders return v; } </quote>
and that code you provided does not work for the PathFor in this example ( copied from your documentation). Do you have any examples of verifiers working in code-first implementations?
|
|
murray.bryant
Groupie
Joined: 11-Jan-2012
Location: Australia
Posts: 44
|
Post Options
Quote Reply
Posted: 07-Feb-2013 at 5:17pm |
Sorry my mistake I worked out the PathFor.
Still struggling with the PropertyMetadata though
|
|
murray.bryant
Groupie
Joined: 11-Jan-2012
Location: Australia
Posts: 44
|
Post Options
Quote Reply
Posted: 07-Feb-2013 at 5:27pm |
So for adding a trigger
v.AddTriggers( Lithology.PropertyMetadata.IntervalFrom.Name, Lithology.PropertyMetadata.IntervalTo.Name);
I can access the PropertyMetadata by adding your previous code
public static IbEm.EntityMetadata PropertyMetadata { get { return IbEm.EntityMetadataStore.Instance.GetEntityMetadata(typeof(Lithology)); } }
to the Lithology Class. However I an unsure as to how to access the property name that the addtrigger code needs.
thanks for you help
|
|
murray.bryant
Groupie
Joined: 11-Jan-2012
Location: Australia
Posts: 44
|
Post Options
Quote Reply
Posted: 07-Feb-2013 at 5:39pm |
Ok it seems I can do the following v.AddTriggers( Sample.EntityPropertyNames.SampleType_id, Sample.EntityPropertyNames.Standard_id
);
|
|