1

I'm trying to write a tool that modifies an edmx file to add a table referenced by a SQL Server Synonym. I'm curious as to whether any of the code the designer already uses is somehow available to me.

To be more precise, I would like to avoid guessing which .NET property types to use in the CSDL to correspond to store provider (SQL Server 2008) property types in the SSDL. The SSDL seems to use straight SQL Server data types, so I have some confidence that SSDL I generate myself will be acceptable to the EDM designer. I want to have at least some confidence that any corresponding CSDL I generate, and the required MSL, will also be acceptable to the designer.

My other question, Entity Framework and SQL Server Synonyms, refers. I am trying to devise a way to add a table aliased by a synonym to an EDMX file.

Community
  • 1
  • 1
ProfK
  • 49,207
  • 121
  • 399
  • 775

1 Answers1

2

The EDMX files are made up of several parts, the CSDL portion describes the conceptual model (classes, properties, function imports etc). The SSDL portion describes the storage model (tables/views, columns, procedures, etc). The MSL portion describes the mapping between the CSDL and SSDL objects. There are also one optional section in the EDMX that describes the designer's diagram layout and that contain other settings related to the designer. The specification for the CSDL, SSDL, and MSL is available on MSDN at: http://msdn.microsoft.com/en-us/library/bb399604.aspx

Alternatively, I have a wrapper library that adds an object model around the EDMX that makes it easier to create, read, and update EDMX files: http://huagati.blogspot.com/2010/12/creating-or-modifying-entity-framework.html

KristoferA
  • 12,287
  • 1
  • 40
  • 62
  • Thanks @KristoferA, your library looks interesting, but I'm not ready for a paid licence yet just for this hobby project. I'm afraid I didn't make my question clear enough before though. I understand all three sections of an EDMX file, and am looking for a way to emulate how Visual Studio generates EDMX data from the database. – ProfK Dec 08 '10 at 03:20
  • Ok, got it. Microsoft has two tools besides the Visual Studio designer, edmgen.exe and edmgen2.exe. Unfortunately they're closed and can't be easily extended, but you _may_ be able to do something with edmgen by replacing the catalog views it uses in the database with new ones that also do synonym lookups. Maybe not ideal, but could work. – KristoferA Dec 08 '10 at 03:54
  • Btw, I'm looking into adding SQL server synonym support to my add-in. Could come in handy... – KristoferA Dec 08 '10 at 03:55
  • Oh, one other potential option: look at the various T4 templates from Microsoft and 3rd parties. VS2010 ships with T4 templates for generating SSDL+MSL from CSDL, and there _might_ be something around for going from SSDL to CSDL. – KristoferA Dec 08 '10 at 03:58
  • Thanks again, @KristoferA. I found edmgen2 via docs for your ad-in, and although the edmx generation uses a closed library, I can extend the source of edmgen2 to generate required edmx for the base table of a synonym, then rename the ssdl elements to point to the prototype. I'll certainly check out the T4 options as well. T4 is lovely stuff. – ProfK Dec 08 '10 at 06:22