{"id":734,"date":"2007-12-26T22:13:00","date_gmt":"2007-12-26T22:13:00","guid":{"rendered":"\/blogs\/bobb\/post\/Mapping-InsertUpdateDelete-sprocs-with-Many-to-Many.aspx"},"modified":"2007-12-26T22:13:00","modified_gmt":"2007-12-26T22:13:00","slug":"mapping-insertupdatedelete-sprocs-with-many-to-many","status":"publish","type":"post","link":"https:\/\/www.sqlskills.com\/blogs\/bobb\/mapping-insertupdatedelete-sprocs-with-many-to-many\/","title":{"rendered":"Mapping Insert\/Update\/Delete sprocs with Many-to-Many"},"content":{"rendered":"<p>\nAfter getting insert\/update\/delete stored procedures going with a simple standalone table (no relationships), I started thinking about how I&#39;d do this in a many-many relationship. Let&#39;s say that I have students and classes, with a many-many relationship represented by a studentclass table with only a student_id and class_id. EDM maps this to a many-many relationship,&nbsp;leaving the &quot;join table&quot; out of the conceptual&nbsp;model (no studentclass entity). That&#39;s what I&#39;d want.&nbsp;But&#8230;how to map insert\/update\/delete on the studentclass table, because there is no entity for it?\n<\/p>\n<p>\nTurns out that this is OK, because mapping insert\/update\/delete to sprocs is not exposed on the entity (CSD layer), but on the mapping (MSD) layer. And, sure enough, there is an ModificationFunctionMapping element exposed under AssociationSetMapping, as well as under EntityTypeMapping. The designer doesn&#39;t support this yet, but the raw XML schema does.\n<\/p>\n<p>\nIn addition, the Entity Framework &quot;Help Overview&quot; file does mention &quot;Mapping Association Sets to stored procedures&quot;. It doesn&#39;t help matters by showing an example of Categories and Products in the Northwind sample database, where the Categories and Products tables don&#39;t have a many-many relationship or a join table. Do I *need* stored procedures on a zero-or-one-many relationship as well as on the &quot;base&quot; tables that comprise the relationship? I can insert and delete a relationship between an existing product and an existing category, so I might need these in addition to the stored procs mapping the base tables, in case these aren&#39;t already enforced by key constraints in the database and model? Doesn&#39;t seem like I&#39;d need them at all, unless I specifically left the appropriate key constraints out of the database, but wanted them in the mapping and conceptual model.\n<\/p>\n<p>\nBut the Help Overview specifically mentions &quot;mapped to a join table in a relationship&quot;, so many-many sounds like to the relationship type (AssociationSet cardinality) I&#39;d need stored procedure mappings for.\n<\/p>\n<p>\nSo there IS a way to do it with many-many.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>After getting insert\/update\/delete stored procedures going with a simple standalone table (no relationships), I started thinking about how I&#39;d do this in a many-many relationship. Let&#39;s say that I have students and classes, with a many-many relationship represented by a studentclass table with only a student_id and class_id. EDM maps this to a many-many relationship,&nbsp;leaving [&hellip;]<\/p>\n","protected":false},"author":7,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12],"tags":[],"class_list":["post-734","post","type-post","status-publish","format-standard","hentry","category-data-access"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v21.9.1 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Mapping Insert\/Update\/Delete sprocs with Many-to-Many - Bob Beauchemin<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.sqlskills.com\/blogs\/bobb\/mapping-insertupdatedelete-sprocs-with-many-to-many\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Mapping Insert\/Update\/Delete sprocs with Many-to-Many - Bob Beauchemin\" \/>\n<meta property=\"og:description\" content=\"After getting insert\/update\/delete stored procedures going with a simple standalone table (no relationships), I started thinking about how I&#039;d do this in a many-many relationship. Let&#039;s say that I have students and classes, with a many-many relationship represented by a studentclass table with only a student_id and class_id. EDM maps this to a many-many relationship,&nbsp;leaving [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.sqlskills.com\/blogs\/bobb\/mapping-insertupdatedelete-sprocs-with-many-to-many\/\" \/>\n<meta property=\"og:site_name\" content=\"Bob Beauchemin\" \/>\n<meta property=\"article:published_time\" content=\"2007-12-26T22:13:00+00:00\" \/>\n<meta name=\"author\" content=\"Bob Beauchemin\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Bob Beauchemin\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/bobb\/mapping-insertupdatedelete-sprocs-with-many-to-many\/\",\"url\":\"https:\/\/www.sqlskills.com\/blogs\/bobb\/mapping-insertupdatedelete-sprocs-with-many-to-many\/\",\"name\":\"Mapping Insert\/Update\/Delete sprocs with Many-to-Many - Bob Beauchemin\",\"isPartOf\":{\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/bobb\/#website\"},\"datePublished\":\"2007-12-26T22:13:00+00:00\",\"dateModified\":\"2007-12-26T22:13:00+00:00\",\"author\":{\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/bobb\/#\/schema\/person\/62bfa986c5b5d28fcffd8b4fc409c73e\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/bobb\/mapping-insertupdatedelete-sprocs-with-many-to-many\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.sqlskills.com\/blogs\/bobb\/mapping-insertupdatedelete-sprocs-with-many-to-many\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/bobb\/mapping-insertupdatedelete-sprocs-with-many-to-many\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.sqlskills.com\/blogs\/bobb\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Data Access\",\"item\":\"https:\/\/www.sqlskills.com\/blogs\/bobb\/category\/data-access\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Mapping Insert\/Update\/Delete sprocs with Many-to-Many\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/bobb\/#website\",\"url\":\"https:\/\/www.sqlskills.com\/blogs\/bobb\/\",\"name\":\"Bob Beauchemin\",\"description\":\"SQL Server Blog\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.sqlskills.com\/blogs\/bobb\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/bobb\/#\/schema\/person\/62bfa986c5b5d28fcffd8b4fc409c73e\",\"name\":\"Bob Beauchemin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/bobb\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/6f80e6cc667410857fa6a21931dc528b8092f4d112bf7a8ff7c267674d44ee37?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/6f80e6cc667410857fa6a21931dc528b8092f4d112bf7a8ff7c267674d44ee37?s=96&d=mm&r=g\",\"caption\":\"Bob Beauchemin\"},\"sameAs\":[\"http:\/www.sqlskills.com\/blogs\/bobb\/\"],\"url\":\"https:\/\/www.sqlskills.com\/blogs\/bobb\/author\/bobb\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Mapping Insert\/Update\/Delete sprocs with Many-to-Many - Bob Beauchemin","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.sqlskills.com\/blogs\/bobb\/mapping-insertupdatedelete-sprocs-with-many-to-many\/","og_locale":"en_US","og_type":"article","og_title":"Mapping Insert\/Update\/Delete sprocs with Many-to-Many - Bob Beauchemin","og_description":"After getting insert\/update\/delete stored procedures going with a simple standalone table (no relationships), I started thinking about how I&#39;d do this in a many-many relationship. Let&#39;s say that I have students and classes, with a many-many relationship represented by a studentclass table with only a student_id and class_id. EDM maps this to a many-many relationship,&nbsp;leaving [&hellip;]","og_url":"https:\/\/www.sqlskills.com\/blogs\/bobb\/mapping-insertupdatedelete-sprocs-with-many-to-many\/","og_site_name":"Bob Beauchemin","article_published_time":"2007-12-26T22:13:00+00:00","author":"Bob Beauchemin","twitter_misc":{"Written by":"Bob Beauchemin","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.sqlskills.com\/blogs\/bobb\/mapping-insertupdatedelete-sprocs-with-many-to-many\/","url":"https:\/\/www.sqlskills.com\/blogs\/bobb\/mapping-insertupdatedelete-sprocs-with-many-to-many\/","name":"Mapping Insert\/Update\/Delete sprocs with Many-to-Many - Bob Beauchemin","isPartOf":{"@id":"https:\/\/www.sqlskills.com\/blogs\/bobb\/#website"},"datePublished":"2007-12-26T22:13:00+00:00","dateModified":"2007-12-26T22:13:00+00:00","author":{"@id":"https:\/\/www.sqlskills.com\/blogs\/bobb\/#\/schema\/person\/62bfa986c5b5d28fcffd8b4fc409c73e"},"breadcrumb":{"@id":"https:\/\/www.sqlskills.com\/blogs\/bobb\/mapping-insertupdatedelete-sprocs-with-many-to-many\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.sqlskills.com\/blogs\/bobb\/mapping-insertupdatedelete-sprocs-with-many-to-many\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.sqlskills.com\/blogs\/bobb\/mapping-insertupdatedelete-sprocs-with-many-to-many\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.sqlskills.com\/blogs\/bobb\/"},{"@type":"ListItem","position":2,"name":"Data Access","item":"https:\/\/www.sqlskills.com\/blogs\/bobb\/category\/data-access\/"},{"@type":"ListItem","position":3,"name":"Mapping Insert\/Update\/Delete sprocs with Many-to-Many"}]},{"@type":"WebSite","@id":"https:\/\/www.sqlskills.com\/blogs\/bobb\/#website","url":"https:\/\/www.sqlskills.com\/blogs\/bobb\/","name":"Bob Beauchemin","description":"SQL Server Blog","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.sqlskills.com\/blogs\/bobb\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.sqlskills.com\/blogs\/bobb\/#\/schema\/person\/62bfa986c5b5d28fcffd8b4fc409c73e","name":"Bob Beauchemin","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.sqlskills.com\/blogs\/bobb\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/6f80e6cc667410857fa6a21931dc528b8092f4d112bf7a8ff7c267674d44ee37?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/6f80e6cc667410857fa6a21931dc528b8092f4d112bf7a8ff7c267674d44ee37?s=96&d=mm&r=g","caption":"Bob Beauchemin"},"sameAs":["http:\/www.sqlskills.com\/blogs\/bobb\/"],"url":"https:\/\/www.sqlskills.com\/blogs\/bobb\/author\/bobb\/"}]}},"_links":{"self":[{"href":"https:\/\/www.sqlskills.com\/blogs\/bobb\/wp-json\/wp\/v2\/posts\/734","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.sqlskills.com\/blogs\/bobb\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.sqlskills.com\/blogs\/bobb\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.sqlskills.com\/blogs\/bobb\/wp-json\/wp\/v2\/users\/7"}],"replies":[{"embeddable":true,"href":"https:\/\/www.sqlskills.com\/blogs\/bobb\/wp-json\/wp\/v2\/comments?post=734"}],"version-history":[{"count":0,"href":"https:\/\/www.sqlskills.com\/blogs\/bobb\/wp-json\/wp\/v2\/posts\/734\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.sqlskills.com\/blogs\/bobb\/wp-json\/wp\/v2\/media?parent=734"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.sqlskills.com\/blogs\/bobb\/wp-json\/wp\/v2\/categories?post=734"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.sqlskills.com\/blogs\/bobb\/wp-json\/wp\/v2\/tags?post=734"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}