none
Property in Entity partial class RRS feed

  • Question

  • I have an entity/table that uses sqlgeography.

    Since EF 4.X doesn't support spatial types I'm instead sending the bytes of the field back and forth.

    I have stored procs on the database side that handles the converstion and properties on the code side to do that job.

    To add the properties in the code I used a partial class.

    One of those properties is for the SqlGeography which simply wraps around the byte[] property to handle getting and setting.

    This property is hidden from EF using the NotMappedAttribute.

    The other is the property exposing the byte[] itself and is decorated with the EdmScalarPropertyAttribute and DataMemberAttribute.

    I then go to the EF model designer (*.edmx) to point the entity model at the Insert/Update/Delete stored procs.

    It finds the stored procs alright and realises that they (when appropriate) take a VARBINARY parameter.

    It also has a drop down allowing you to select a property on the entity class which maps to that parameter.

    However this drop down doesn't list either of my properties. I don't care about the SqlGeography property since that is meant to be hidden from EF, however it is vital for me to be able to point it at the byte[] property, as that is where the data comes from.

    I would very much like to avoid database triggers or wrapper classes and addiitonal fields to fudge this in to working.

    I tried manually editing the .edmx file to include the byte[] property, but then it just complains it's unmapped.

    Can anyone give me some insight in to how to get this to work? Or an alternative method of achiving the end result?

    • Edited by Andy Jump Wednesday, February 8, 2012 5:11 PM
    Wednesday, February 8, 2012 4:55 PM

Answers

  • Hi Andy;

    Have you read the following article by Julie Lerman

    Yes you can read (and probably write) Spatial Data with Entity Framework

    Maybe it will help.


    Fernando (MCSD)

    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".

    • Marked as answer by Andy Jump Thursday, February 9, 2012 9:46 AM
    Wednesday, February 8, 2012 5:46 PM
  • So it turns out if you're going to use a view you'll then have to manually write all the xml to impliment the relationships that are now hidden.

    This pretty much voids the point of using EF which is to make life simple and easy ;)

    For this instance we've plumped for having a binary field and a geography field and then handling the two using sprocs for insertion and properties in the partial entity class for use in the app.

    Next project we won't bother with EF.

    • Marked as answer by Andy Jump Thursday, February 9, 2012 9:46 AM
    Thursday, February 9, 2012 9:46 AM

All replies

  • Hi Andy;

    Have you read the following article by Julie Lerman

    Yes you can read (and probably write) Spatial Data with Entity Framework

    Maybe it will help.


    Fernando (MCSD)

    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".

    • Marked as answer by Andy Jump Thursday, February 9, 2012 9:46 AM
    Wednesday, February 8, 2012 5:46 PM
  • Ahhh!

    Yes, making a view should sort it out.

    I already have the stored procs for inserting and updating that handle the data going in to the database, and this should fix my problems for data coming out.

    Thanks for the link!

    I'll try implimenting it now.

    Thursday, February 9, 2012 8:48 AM
  • So it turns out if you're going to use a view you'll then have to manually write all the xml to impliment the relationships that are now hidden.

    This pretty much voids the point of using EF which is to make life simple and easy ;)

    For this instance we've plumped for having a binary field and a geography field and then handling the two using sprocs for insertion and properties in the partial entity class for use in the app.

    Next project we won't bother with EF.

    • Marked as answer by Andy Jump Thursday, February 9, 2012 9:46 AM
    Thursday, February 9, 2012 9:46 AM