[{"data":1,"prerenderedAt":112},["ShallowReactive",2],{"tag-entityframework":3},{"tag":4,"articles":24},{"id":5,"title":6,"body":7,"description":14,"extension":15,"img":16,"meta":17,"name":18,"navigation":19,"path":20,"seo":21,"stem":22,"__hash__":23},"tags\u002Ftags\u002Fentityframework.md","Entityframework",{"type":8,"value":9,"toc":10},"minimark",[],{"title":11,"searchDepth":12,"depth":12,"links":13},"",2,[],"Entity Framework is an open-source ORM framework for .NET applications supported by Microsoft. It enables developers to work with data using objects of domain specific classes without focusing on the underlying database tables and columns where this data is stored.","md","https:\u002F\u002Fimages.unsplash.com\u002Fphoto-1598313183973-4effcded8d5e?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=675&q=80",{},"entityframework",true,"\u002Ftags\u002Fentityframework",{"description":14},"tags\u002Fentityframework","OUnoZJoIvU2LISfVORR0X4iRDBwmF8VkIoyT75FfFJw",[25],{"id":26,"title":27,"author":28,"body":29,"createdAt":104,"description":105,"extension":15,"img":93,"meta":106,"navigation":19,"path":107,"seo":108,"stem":109,"tags":110,"updatedAt":104,"__hash__":111},"articles\u002Farticles\u002Fentity-framework-and-primary-keys.md","Entity Framework and Primary Keys","[object Object]",{"type":8,"value":30,"toc":102},[31,35,42,76,79,98],[32,33,34],"p",{},"Entity Framework relies on primary keys with views and tables.  If you are trying to bring a view into dbContext, and the view does not have a primary key the following should help you out.  The schema object has to have primary key defined and it be set to not allow nulls (not-null).",[32,36,37,38,41],{},"The solution for me was to refashion my view definition using RowId like the following",[39,40],"br",{},"\nThis will create a non-null RowId for each row in the result.",[43,44,48],"pre",{"className":45,"code":46,"language":47,"meta":11,"style":11},"language-sql shiki shiki-themes github-light github-dark","SELECT ISNULL(ROW_NUMBER() OVER(ORDER BY P1), -1) \nAS RowID, P1 AS Code, P3, P2\nFROM dbo.BigTable \nWHERE P1 IS NOT NULL\n","sql",[49,50,51,59,64,70],"code",{"__ignoreMap":11},[52,53,56],"span",{"class":54,"line":55},"line",1,[52,57,58],{},"SELECT ISNULL(ROW_NUMBER() OVER(ORDER BY P1), -1) \n",[52,60,61],{"class":54,"line":12},[52,62,63],{},"AS RowID, P1 AS Code, P3, P2\n",[52,65,67],{"class":54,"line":66},3,[52,68,69],{},"FROM dbo.BigTable \n",[52,71,73],{"class":54,"line":72},4,[52,74,75],{},"WHERE P1 IS NOT NULL\n",[32,77,78],{},"After you create the view take a look at the view definition within SQL Server Management Studio.  You should see that you have defined a column RowId which is non-null. ",[32,80,81,82,84],{},"This will satisfy Entity Framework and dbContext can now include a reference to these views or tables.",[39,83],{},[85,86,89],"a",{"style":87,"href":88},"display: none;","\u002Farticles\u002Fimages\u002Fopen-live-writer-entity-framework-and-primary-keys_eb29-ef_2.png",[90,91],"img",{"style":92,"src":93,"border":94,"alt":95,"title":95,"width":96,"height":97},"background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;","\u002Farticles\u002Fimages\u002Fopen-live-writer-entity-framework-and-primary-keys_eb29-ef_thumb.png",0,"ef",240,154,[99,100,101],"style",{},"html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}",{"title":11,"searchDepth":12,"depth":12,"links":103},[],"2017-01-18T09:49:20.3800000-05:00","Entity Framework relies on primary keys with views and tables...",{},"\u002Farticles\u002Fentity-framework-and-primary-keys",{"title":27,"description":105},"articles\u002Fentity-framework-and-primary-keys",[18],"LlkG54x3JZij2W3gLKsdJshQfKO6dv1t6tzMvSrv9wQ",1781574759083]