We have a set of views (a lot) that we are trying to implement in the Entity Framework with our relationships. These views have primary keys defined , but for some reason, when I create an Entity model for them, I received a message:
There is no primary key in the table / view of 'vwFoo'. The key was and the definition was created as a table / read-only view.
In addition, to make them read-only, which we do not want, relationships are not preserved. Is there a way to get them to load correctly into the model?
The base database is SQL Server 2005, but we also need to support 2000.
Any help would be appreciated
UPDATE AND DECISION
Here's an XSLT transform that worked successfully to turn two views from our EDMX into tables. This has two problems: 1) adding bad xmlns = "" attributes and 2) setting the UTF-8 encoding incorrectly. I fixed both of them in a separate Perl script.
<?xml version="1.0" encoding="utf-8" ?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:edmx="http://schemas.microsoft.com/ado/2007/06/edmx" xmlns:store="http://schemas.microsoft.com/ado/2007/12/edm/EntityStoreSchemaGenerator" xmlns:ssdl="http://schemas.microsoft.com/ado/2006/04/edm/ssdl" xmlns:edm="http://schemas.microsoft.com/ado/2006/04/edm" xmlns:cs="urn:schemas-microsoft-com:windows:storage:mapping:CS" exclude-result-prefixes="ssdl edm store cs" version="1.0"> <xsl:output method="xml"/> <xsl:template match="@* | node()"> <xsl:copy> <xsl:apply-templates select="@* | node()"/> </xsl:copy> </xsl:template> <xsl:template match="edmx:Edmx/edmx:Runtime/edmx:StorageModels/ssdl:Schema/ssdl:EntityType[@Name='vwPerson']/ssdl:Key"> <Key> <PropertyRef Name="fkPersonID" /> </Key> </xsl:template> <xsl:template match="edmx:Edmx/edmx:Runtime/edmx:ConceptualModels/edm:Schema/edm:EntityType[@Name='vwPerson']/edm:Key"> <Key> <PropertyRef Name="fkPersonID" /> </Key> </xsl:template> <xsl:template match="edmx:Edmx/edmx:Runtime/edmx:StorageModels/ssdl:Schema/ssdl:EntityContainer/ssdl:EntitySet[@Name='vwPerson']"> <EntitySet Name="vwPerson" EntityType="DataMachineModel.Store.vwPerson" store:Type="Tables" Schema="dbo" /> </xsl:template> <xsl:template match="edmx:Edmx/edmx:Runtime/edmx:StorageModels/ssdl:Schema/ssdl:EntityType[@Name='vwPersonAddress']/ssdl:Key"> <Key> <PropertyRef Name="PersonID" /> </Key> </xsl:template> <xsl:template match="edmx:Edmx/edmx:Runtime/edmx:ConceptualModels/edm:Schema/edm:EntityType[@Name='vwPersonAddress']/edm:Key"> <Key> <PropertyRef Name="PersonID" /> </Key> </xsl:template> <xsl:template match="edmx:Edmx/edmx:Runtime/edmx:StorageModels/ssdl:Schema/ssdl:EntityContainer/ssdl:EntitySet[@Name='vwPersonAddress']"> <EntitySet Name="vwPersonAddress" EntityType="DataMachineModel.Store.vwPersonAddress" store:Type="Tables" Schema="dbo" /> </xsl:template> </xsl:stylesheet>
This seems to work as creating views is like tables; however, he does not maintain a relationship between them. I tried adding FK associations to EDMX through XSLT, but was not successful.
We decided to make real tables from our representations and transfer the presentation logic to a separate class that can filter the data we need.
source share