Add "customattribute" to entities

Discussion of open issues, suggestions and bugs regarding Entity Developer - ORM modeling and code generation tool
Post Reply
rbrink
Posts: 1
Joined: Tue 06 Oct 2020 10:48

Add "customattribute" to entities

Post by rbrink » Tue 06 Oct 2020 10:57

Hi,

Is it possible to add a custom annotation to an entity using Entity Developer? What I mean by this is the following:

<EntityType Name="CartItem" customannotation:ClrType="EntityModel.CartItem">
or
<EntityType Name="CartItem" customannotation:ClrType="MyApp.CartItem, MyApp, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null">

The reason I ask this is because we suffer from an Entity Framework issue:
`System.Data.Entity.Core.MetadataException: Schema specified is not valid. Errors:
The mapping of CLR type to EDM type is ambiguous because multiple CLR types match the EDM type 'Translation'. `
More here: https://stackoverflow.com/questions/149 ... ith-ef-6-5

This error occurs because we use two separate data models in our application (both created with Entity Developer btw) and both contain an entity named `Translation` in this case.

To overcome this error we'd like to add the above `customannotation` as mentioned in the thread on Stackoverflow (see link above).

Is this even possible?

We use Entity Developer 6.6.894, Entity Framework 6.2.0 and SQL Server 2017 for the database.

Cheers,
Raymond

Shalex
Site Admin
Posts: 9543
Joined: Thu 14 Aug 2008 12:44

Re: Add "customattribute" to entities

Post by Shalex » Mon 12 Oct 2020 15:30

Refer to https://github.com/dotnet/ef6/issues/362:
When using Code First in EF6, having another type with the same simple name as a type that is mapped will no longer cause problems
With Devart Entity Model (*.edml), you can use two approaches:

1. Fluent (or attribute) mapping. There should be no error in this case. Make the following settings to use it:
a) disable default EntityObject template and enable DbContext template via Tools > Entity Developer > Model Explorer > the Templates node. Set Fluent Mapping = True in the properties of the DbContext template. Also you can change value of the Mapping Generation Strategy property
b) select designer surface and set Metadata Artifact Processing = Do Not Generate Mapping Files in the properties of EntityContextModel

2. XML mapping. It is generated by DbContext (when Fluent Mapping=False) and by EntityObject templates. We will investigate the possibility to add a custom annotation to an entity for this scenario.

Post Reply