msawczyn/EFDesigner

Custom datatypes get lost after adding properties via code

alprinias opened this issue · 5 comments

During importing a model from a compiled assembly (which was created from scaffolding an existing database) I noticed the following:

All tables of the old database I'm trying to import in the designer had a "Timestamp" column of "timestamp" type in the SQL Server, which was scaffolded as Byte[]. It shows, indeed, as Timestamp:Byte[] in the designer. When I open the "Add properties via code" popup to edit a property, I can see the Timestamp:Byte[] in the list. However, when I finish editing and close the popup, the Timestamp property gets deleted from the designer. It looks like the Byte[] is not recognized and is discarded. I suppose that the empty square brackets are not acceptable in the translation, as the translator expects a number in the brackets for the length.

So, I went on to define the property again in the designer, give it a type of Byte (not Byte array) and a Column Type of "timestamp". However, if I open again the Add Properties via Code and make any change to any property, the custom Column Types are lost after saving. Which I discovered is true also for all the decimal properties, for the Column Types of which I had set e.g. "decimal(10, 4)".

I've made a change to translate byte[] to Binary for the model attribute type. Specifying the scale and precision of a decimal isn't supported in the designer yet, but is on the list now that EFCore5 is out.

Thanks.
I don't find it necessary to specify scale and precision in the designer. What would be useful is, whatever has been defined as custom column type to be left intact after the "add properties via code" popup is closed. But I presume you delete and re-write all of them at that point... Anyway, it's not crucial.

Released in 3.0.1

Hi Alex,

Publishing to the marketplace and publishing to Github are separate things, and are manual processes that don't relate to each other. When 3.5.0.2 was published to the Marketplace, I had neglected to publish a release on Github. Normally, Github will have releases that are more recent then the Marketplace, marked as pre-release, but this was human error.

The designer doesn't look to see what version of the EF assembly is available; it only looks to see which one is specified in the model properties. So if the model specified a distinct version, it should be using that.

To validate that, you can put a breakpoint on any usage of ModelRoot.GetEntityFrameworkPackageVersionNum() where the ModelRoot is available -- easiest place is in the root .tt file for your model -- and see what it returns. That switch statement determines which branch of the code generation template versions will be followed.

Cheers,
-- Michael