Question

I'm trying to interface my PostgreSQL database using Microsoft entity framework.

As the npgsql database provider does not integrate into visual studio I'm using the EdmGen tool to generate the interface code from my existing database.

The database also includes a stored procedure for testing purpose: it takes no parameter and returns void. EdmGen does not generate any code for this stored procedure - but it is included in the generated ssdl file. So I wrote a little tool that modifies the csdl and msl files to include this procedure as well. This is the boiled down view of the three files:

ssdl:

<Schema Namespace="Test.Store" Alias="Self" Provider="Npgsql" ProviderManifestToken="9.2.4" xmlns:store="http://schemas.microsoft.com/ado/2007/12/edm/EntityStoreSchemaGenerator" xmlns="http://schemas.microsoft.com/ado/2009/11/edm/ssdl">
  <Function Name="TestFunc" Aggregate="false" BuiltIn="false" NiladicFunction="false" IsComposable="false" ParameterTypeSemantics="AllowImplicitConversion" Schema="public" />
</Schema>

csdl:

<Schema Namespace="Test" Alias="Self" p1:UseStrongSpatialTypes="false" xmlns:annotation="http://schemas.microsoft.com/ado/2009/02/edm/annotation" xmlns:p1="http://schemas.microsoft.com/ado/2009/02/edm/annotation" xmlns="http://schemas.microsoft.com/ado/2009/11/edm">
  <EntityContainer Name="TestContext" p1:LazyLoadingEnabled="true">
    <FunctionImport Name="TestFunc" IsComposable="false" />
  </EntityContainer>
</Schema>

msl:

<Mapping Space="C-S" xmlns="http://schemas.microsoft.com/ado/2009/11/mapping/cs">
  <EntityContainerMapping StorageEntityContainer="TestStoreContainer" CdmEntityContainer="TestContext">
     <FunctionImportMapping FunctionImportName="TestFunc" FunctionName="Test.Store.TestFunc" />
  </EntityContainerMapping>
</Mapping>

The code generated by EdmGen looks like this:

public int TestFunc()
{
    return base.ExecuteFunction("TestContext.TestFunc");
}

I call this function using this code:

using (var ctx = new TestContext())
{
    ctx.TestFunc();
}

But I get the following exception:

[System.Data.EntityCommandCompilationException]
An error occurred while preparing the command definition. See the inner exception for details.

The inner exception is:

[System.ArgumentException]
Value does not fall within the expected range.

I have no idea where this exception is coming from as there are no value to be passed to or from the stored procedure. Maybe you guys can help me.

Points that might also be important:

  • This is connection string in my app.config:

    <connectionStrings>
        <add name="TestContext" 
             providerName="System.Data.EntityClient" 
             connectionString="metadata=res://Test/Test.Database.Test.csdl|res://Test/Test.Database.Test.ssdl|res://Test/Test.Database.Test.msl; provider=Npgsql; provider connection string=&quot;Server=localhost;Port=5432;Database=Test;User Id=xxx;Password=xxx;enlist=true;&quot;"/>
    </connectionStrings>
    
  • I'm using the following software versions:

    • Visual Studio Express for Desktop 2012
    • npgsql 2.0.11.0
  • I'm completely new to Entity Framework and ADO.NET, also I'm quite new to C#, .NET and Visual Studio. So I might have misunderstood some concepts.

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top