Code gen compile error ...

Discussion of open issues, suggestions and bugs regarding Entity Developer - ORM modeling and code generation tool
Post Reply
Stuart.Stephens
Posts: 7
Joined: Thu 03 Mar 2011 19:59

Code gen compile error ...

Post by Stuart.Stephens » Thu 03 Mar 2011 20:19

This morning I tried to serialize some new objects I created via the Entity Developer.

I messed with templates first (http://www.devart.com/forums/viewtopic. ... rializable), adding a attribute to my classes. This approach does not work as it will yield the dreaded "Type 'System.Data.Linq.EntitySet`1[*]' in Assembly '*' is not marked as serializable" error. Pretty much a dead end there.

Then I ran across a post from Rick Strahl (http://west-wind.com/weblog/posts/147218.aspx) so it looked like my next approach was to change the Model Properties -> Model -> Serialization Mode to "Unidirectional" and see what happens.

Curiously, this seems to has exposed a bug in the codegen logic, as there is a syntax error in the resulting output. Here is an example (note the rogue ">" at the end of the first occurrence of "Of BusinessAddress"):

Code: Select all

        Private Sub Initialize()
            Me._BusinessAddress = new EntitySet(Of BusinessAddress>(new Action(AddressOf Me.attach_BusinessAddress), new Action<BusinessAddress)(AddressOf Me.detach_BusinessAddress))
            ...
        End Sub
I am currently using Version 2.80.167.

Please advise on how to proceed.

Stuart

StanislavK
Devart Team
Posts: 1710
Joined: Thu 03 Dec 2009 10:48

Post by StanislavK » Fri 04 Mar 2011 07:41

This is a known problem of Entity Developer 2.80.167 which was fixed in the 3.0.60 build. Please try updating to the latest 3.20.89 version and tell us if the problem persists. Provided that you have an active subscription, you can download the latest version of Entity Developer (or data provider you are using) from Registered Users' Area:
http://secure.devart.com/

You may need to contact our Sales department to receive the credentials for the new version: sales * devart * com .

Stuart.Stephens
Posts: 7
Joined: Thu 03 Mar 2011 19:59

Post by Stuart.Stephens » Fri 04 Mar 2011 17:21

We do have a subscription for my department. I checked with one of our guys on the version yesterday (they just had us upgrade) and he indicated we had the most current at which point I posted to the forums.

I will follow up with them on the issue.

Thanks for the quick reply!

Regards,

Stuart

Stuart.Stephens
Posts: 7
Joined: Thu 03 Mar 2011 19:59

Post by Stuart.Stephens » Fri 04 Mar 2011 23:51

We were on the most current version of the 5.x product. Our admin pulled down the 6.x product for me, which I installed.

It was an adventure, but I think I got it. The "Unidirectional" config change was definately the first step in the right direction and got me a new set of exceptions. I spent the fair part of today messing with it. I finally found a tweak in the codegen template that got it working.

Specifically, the DataContract class attribute needed IsReference set to true, which in the template should look like this (after editing):

Code: Select all

#>
     _
<#
I was then able to whip up some serialize/deserialize methods like this (will add try/catch later - just got this limping):

Code: Select all

        Public Shared Function Serialize(ByVal o As Object) As String
            Dim sb As StringBuilder = New StringBuilder()
            Dim dcs As New System.Runtime.Serialization.DataContractSerializer(o.GetType)
            Dim writer As System.Xml.XmlWriter = System.Xml.XmlWriter.Create(sb)

            dcs.WriteObject(writer, o)
            writer.Close()

            Return sb.ToString()
        End Function

        Public Shared Function Deserialize(ByVal s As String, ByVal t As System.Type) As Object
            Dim o As Object
            Dim dcs As New System.Runtime.Serialization.DataContractSerializer(t)
            Dim reader As System.Xml.XmlReader = System.Xml.XmlReader.Create(New System.IO.StringReader(s))

            o = dcs.ReadObject(reader, True)
            reader.Close()

            Return o
        End Function
This seems to be working, at least topically (I haven't fully populated an extensive model - just playing with a few test objects)

Would it make more sense to expose the IsReference property via the GUI to avoid having to template hack? The entities would not serialize without this property and I don't have circular references. I can't help but think anyone else that trys this will run into the same issue.

Thanks,

Stuart

StanislavK
Devart Team
Posts: 1710
Joined: Thu 03 Dec 2009 10:48

Post by StanislavK » Mon 07 Mar 2011 15:12

Thank you for your suggestion, we will consider adding an option that will control this behaviour.

Could you please specify why your entities cannot be serialized with the default false value of IsReference? If possible, please describe the structure of your entities being serialized, or send us a sample model. This would help our investigation greatly.

Stuart.Stephens
Posts: 7
Joined: Thu 03 Mar 2011 19:59

Post by Stuart.Stephens » Tue 08 Mar 2011 00:32

One more follow up issue regarding this thread ...

I got everything working (see above) and did my check in today. This broke another developer.

What appears to be happening is adding a new template creates (1) a file (*.tmpl) and (2) a registry entry (HKCU/Software/DevArt/Entity Developer/TemplateItems) with the template name and path. It appears that the GUI for the entity developer only knows about templates listed in this registry entry. Consequently, other developers can't compile with my template (they get an error because the *.lqml file doesn't know where to get the template).

We can work around this by manually adding a template of the same name/path and then recovering our work from SVN, but this is kind of kludgy.

I would suggest the *.lqml file directly referencing the templates leaving the registry completely out of the picture.

Regards,

Stuart

Stuart.Stephens
Posts: 7
Joined: Thu 03 Mar 2011 19:59

Post by Stuart.Stephens » Wed 09 Mar 2011 22:36

I think I might be able to shed some light on the serialization conditions you asked about (I skimmed your post too quickly and my boss followed up with me). I would like some feedback regarding the request so I can pass back to my boss (both the IsReference concern and the template concern).

We just came off of 5.x of the product to 6.x. We do not use the many-to-many feature in 6.x (we just figured out we had to disable it as it was messing with our model). That is to say we explicitly maintain our many-to-many tables in the ED.

It appears that a many-to-many table can not serialize all of its FK objects. So, lets say we have a many-to-many table, MtM, which refers to A and Z, I can serialize Z, which serializes its MtM, but the MtM doesn't serialize its A (it serializes the ID for A, but not the whole object). If I attempt this without the IsReference I get an error claiming circular references.

Hope that helps.

Let me know if you need additional information.

Regards,

Stuart

StanislavK
Devart Team
Posts: 1710
Joined: Thu 03 Dec 2009 10:48

Post by StanislavK » Thu 10 Mar 2011 15:26

We plan to implement substantial changes to the way of working with templates in the next minor version (not build) of Entity Developer. In particular, the problem with registry entries should be fixed.

Thank you for the clarifications. We will post here when new information about either of the issues is available.

Stuart.Stephens
Posts: 7
Joined: Thu 03 Mar 2011 19:59

Post by Stuart.Stephens » Thu 10 Mar 2011 17:03

Thank you for the response.

Regards,

Stuart

StanislavK
Devart Team
Posts: 1710
Joined: Thu 03 Dec 2009 10:48

Post by StanislavK » Wed 27 Apr 2011 10:17

We have released the new 3.50.116 Beta version of Entity Developer (included into the corresponding Beta versions of Devart data providers). In the new version, no registry entries are created for custom templates, and it is possible to create a template that is 'visible' to an only model. For more details concerning the improvements in working with code generation templates, please refer to
http://www.devart.com/forums/viewtopic.php?t=20826

The Beta version can be downloaded from
http://www.devart.com/entitydeveloper/download.html
(the trial of Entity Developer for SQL Server). For the versions supporting other DBMSs, please download the Beta version of the corresponding data provider:
http://www.devart.com/dotconnect/

The registered versions of Entity Developer 3.50 Beta are available at Registered Users' Area (for users with active subscription only):
http://secure.devart.com/

StanislavK
Devart Team
Posts: 1710
Joined: Thu 03 Dec 2009 10:48

Post by StanislavK » Fri 17 Jun 2011 16:30

We have changed the code generation templates so that the 'IsReference' serialization mode is now used. This change is available in the new 3.50.134 build of Entity Developer (and in the new builds of data providers and LinqConnect as well). The new build of Entity Developer for SQL Server can be downloaded from
http://www.devart.com/entitydeveloper/download.html
(the trial and free versions) and from Registered Users' Area (for users with active subscription only):
http://secure.devart.com/

For more information about the fixes and improvements available in Entity Developer 3.50.134, please refer to
http://www.devart.com/forums/viewtopic.php?t=21283

Post Reply