views:

52

answers:

1

I try to use the new POCO capabilities of EF 4.0 in combination with the EFOracleProvider. I have recompiled the EFOracleProvider (using ODAC instead of System.Data.OracleClient) to target the .NET Framework 4 (und put it in the 4.0 GAC). Everything ok so far.

I host the Entity Model in a WCF Data Service:

class DivaDispoDataService : DataService<DivaDispoContainer>
{
    public static void InitializeService(IDataServiceConfiguration config)
    {
        config.SetEntitySetAccessRule("*", EntitySetRights.All);
        config.SetServiceOperationAccessRule("*", ServiceOperationRights.All);
    }
}

My EDMX File looks like this:

<?xml version="1.0" encoding="utf-8"?>
<edmx:Edmx Version="2.0" xmlns:edmx="http://schemas.microsoft.com/ado/2008/10/edmx"&gt;
  <!-- EF Runtime content -->
  <edmx:Runtime>
    <!-- SSDL content -->
    <edmx:StorageModels>
      <Schema xmlns="http://schemas.microsoft.com/ado/2009/02/edm/ssdl"  xmlns:store="http://schemas.microsoft.com/ado/2007/12/edm/EntityStoreSchemaGenerator" Namespace="DivaDispo.Store" Alias="Self" Provider="EFOracleProvider" ProviderManifestToken="10g">
        <EntityContainer Name="DivaDispoStoreContainer">
          <EntitySet Name="DIW_USER" EntityType="DivaDispo.Store.DIW_USER" store:Type="Tables" Schema="" />
        </EntityContainer>
        <EntityType Name="DIW_USER">
          <Key>
            <PropertyRef Name="IDX" />
          </Key>
          <Property Name="IDX" Type="number" Nullable="false" Precision="10" />
          <Property Name="USERNAME" Type="number" Precision="10" />
          <Property Name="PERSONNELNUMBER" Type="number" Precision="10" />
          <Property Name="PASSWORD" Type="varchar2" MaxLength="10" />
          <Property Name="ACTIVATED" Type="number" Precision="1" />
          <Property Name="ROLE" Type="number" Precision="1" />
        </EntityType>
      </Schema>
    </edmx:StorageModels>
    <!-- CSDL content -->
    <edmx:ConceptualModels>
      <Schema xmlns="http://schemas.microsoft.com/ado/2008/09/edm"  xmlns:cg="http://schemas.microsoft.com/ado/2006/04/codegeneration" xmlns:store="http://schemas.microsoft.com/ado/2007/12/edm/EntityStoreSchemaGenerator" Namespace="DivaDispo.Model" Alias="Self" xmlns:annotation="http://schemas.microsoft.com/ado/2009/02/edm/annotation"&gt;
        <EntityContainer Name="DivaDispoContainer" annotation:LazyLoadingEnabled="false">
          <EntitySet Name="User" EntityType="DivaDispo.Model.User" />
        </EntityContainer>
        <EntityType Name="User">
          <Key>
            <PropertyRef Name="ID" />
          </Key>
          <Property Name="ID" Type="Decimal" Nullable="false" Precision="10" Scale="0"    />
          <Property Name="Username" Type="Decimal" Precision="10" Scale="0" />
          <Property Name="PersonnelNumber" Type="Decimal" Precision="10" Scale="0" />
          <Property Name="Password" Type="String" MaxLength="10" Unicode="false"  FixedLength="false" />
          <Property Name="Activated" Type="Boolean" />
          <Property Name="Role" Type="Boolean" />
        </EntityType>
      </Schema>
    </edmx:ConceptualModels>
    <!-- C-S mapping content -->
    <edmx:Mappings>
      <Mapping xmlns="http://schemas.microsoft.com/ado/2008/09/mapping/cs" Space="C-S">
        <EntityContainerMapping StorageEntityContainer="DivaDispoStoreContainer" CdmEntityContainer="DivaDispoContainer">
          <EntitySetMapping Name="User">
            <EntityTypeMapping TypeName="IsTypeOf(DivaDispo.Model.User)">
              <MappingFragment StoreEntitySet="DIW_USER">
                <ScalarProperty Name="ID" ColumnName="IDX" />
                <ScalarProperty Name="Username" ColumnName="USERNAME" />
                <ScalarProperty Name="PersonnelNumber" ColumnName="PERSONNELNUMBER" />
                <ScalarProperty Name="Password" ColumnName="PASSWORD" />
                <ScalarProperty Name="Activated" ColumnName="ACTIVATED" />
                <ScalarProperty Name="Role" ColumnName="ROLE" />
              </MappingFragment>
            </EntityTypeMapping>
          </EntitySetMapping>
        </EntityContainerMapping>
      </Mapping>
    </edmx:Mappings>
  </edmx:Runtime>
</edmx:Edmx>

My POCO Class looks like this:

public partial class User
{
    public virtual decimal ID { get; set; }
    public virtual Nullable<decimal> Username { get; set; }
    public virtual Nullable<decimal> PersonnelNumber { get; set; }
    public virtual string Password { get; set; }
    public virtual Nullable<bool> Activated { get; set; }
    public virtual Nullable<bool> Role { get; set; }
 }

and the DataContext like this:

public partial class DivaDispoContainer : ObjectContext
{
    public const string ConnectionString = "name=DivaDispoContainer";
    public const string ContainerName = "DivaDispoContainer";

    #region Constructors

    public DivaDispoContainer()
        : base(ConnectionString, ContainerName)
    {
        this.ContextOptions.LazyLoadingEnabled = false;
    }

    public DivaDispoContainer(string connectionString)
        : base(connectionString, ContainerName)
    {
        this.ContextOptions.LazyLoadingEnabled = false;
    }

    public DivaDispoContainer(EntityConnection connection)
        : base(connection, ContainerName)
    {
        this.ContextOptions.LazyLoadingEnabled = false;
    }

    #endregion

    #region ObjectSet Properties

    public ObjectSet<User> User
    {
        get { return _user  ?? (_user = CreateObjectSet<User>("User")); }
    }
    private ObjectSet<User> _user;
  }

The POCO classes and the DataContext are generated with the POCO Template from Visual Studio 2010.

When I start my WCF Service and want to query the users I receive an System.Data.Services.DataServiceException which says somtihng like

500: Internal Server error. The type 'System.Data.Entity.DynamicProxies.User_057822846B2B8DD7BB03058490B27D19E6C634EACF33438FE886  19C8BBB1CF74' is not a komplex type or entity type. 

When I look in the dubgger I can see that the values have been read from the database (therefore I think the EFOracleProvider works ok) and that the DynamicProxies.User_.... is derrived from my User class (which contains at that point the data from the database). So the question is: Why do I receive this exception? Does anyone know whats going on there? What's the DynamicProxies.User_.... automaic generated class for? The Exception is thrown in the Method GetNonPrimitiveResourceType of the class WebUtil. Or maybe I have something overlooked?

Any help greatly appreciated....

+1  A: 

The link from Craig to the blog post http://msdn.microsoft.com/en-us/library/ee705457.aspx revealed the answer. It states there that

The POCO proxy type cannot be directly serialized or deserialized by WCF 

and that is exactly my problem. If I remove the virtual from the properties of the genrated POCO class the runtime doesnt generate the proxy types and the exception dissapears.

Thanks again for the link, Craig.