How to: Map a GUID Property to a Binary Column

This topic describes how to manually edit an .edmx file to map a binary column that stores uniqueidentifier values in the data source to a GUID property in the conceptual model. When you generate or update a data model with the Entity Data Model Wizard or the Update Model Wizard, GUID properties of entity types are automatically generated for uniqueidentifier-typed columns in the data source. A data source may also use 16-byte binary columns to store GUID values. Because the tools generate a binary property for each binary column in the data source, you must manually update the mapping of such columns to GUID properties by editing the .edmx file.

The procedure in this topic assumes that you have a valid .edmx file open in Visual Studio.

Note

Changes made to the SSDL section of an .edmx file, as suggested in the following procedures, will be overwritten if you use the Update Model Wizard to update your model.

To map a GUID property to a binary column that contains GUID values

  1. In the Entity Data Model Designer, select the property to change to a GUID type.

  2. In the Properties window, change the type from Binary to Guid.

    A mapping error will occur if you try to build the project at this point.

  3. Save the model, close the Entity Data Model Designer, and open the .edmx file by using XML Editor.

  4. In the SSDL section, locate the binary property that corresponds to the GUID property in the CSDL section.

  5. Change the value of the Type attribute of this property to uniqueidentifier. For more information, see Property Element (EntityType SSDL).

  6. Save changes to the model and rebuild the solution to regenerate the data classes.