views:

29

answers:

1

I have been working on this problem for too long. All of my select and insert commands work fine but when it comes to updating decimal columns i get errors.

I am using the following software

  • ASP.Net v4
  • MySQL Connector Net 6.3.3
  • MySql Server 5.0.51a

Product Class

public class Product()
{
    public int ProductID {get;set;}
    public string Name {get;set;}
    public decimal Price {get;set;}
    public string Description {get;set;}
}

The Code producing the error

var context = ObjectContextHelper.CurrentObjectContext;

var item = GetProductByID(ProductID);

if (!context.IsAttached(item))
    context.Product.Attach(item);

item.Barcode = Barcode;
item.Price = Price;
item.ProductID = ProductID;
item.Name = Name;
item.Description = Description;

context.SaveChanges();

Database Schema

CREATE TABLE `product` (
  `ProductID` int(10) unsigned NOT NULL auto_increment,
  `Name` varchar(45) character set latin1 default NULL,
  `Description` text character set latin1,
  `Price` decimal(10,2) default NULL,
  PRIMARY KEY  (`ProductID`)
) ENGINE=MyISAM AUTO_INCREMENT=154 DEFAULT CHARSET=utf8 PACK_KEYS=1$$

The inner exception error i receive is

InnerException = {"The specified value is not an instance of type 'Edm.Int64'\r\nParameter name: value"}

The error doesn't fire if you stop the update to the Price Column.

This is the Entity Mappings

    <?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 Namespace="Wombat.Store" Alias="Self" Provider="MySql.Data.MySqlClient" ProviderManifestToken="5.0" xmlns:store="http://schemas.microsoft.com/ado/2007/12/edm/EntityStoreSchemaGenerator" xmlns="http://schemas.microsoft.com/ado/2009/02/edm/ssdl"&gt;
        <EntityContainer Name="WombatStoreContainer">
          <EntitySet Name="product" EntityType="Wombat.Store.Product" store:Type="Tables" Schema="charlees" />

        </EntityContainer>
        <EntityType Name="product">
          <Key>
            <PropertyRef Name="ProductID" />
          </Key>
          <Property Name="Price" Type="decimal" Scale="2" />
          <Property Name="ProductID" Type="uint" Nullable="false" StoreGeneratedPattern="Identity" />
          <Property Name="Name" Type="varchar" MaxLength="45" />
          <Property Name="Description" Type="text" />

        </EntityType>

        <Function Name="isNullDecimal" ReturnType="decimal" Aggregate="false" BuiltIn="false" NiladicFunction="false" IsComposable="true" ParameterTypeSemantics="AllowImplicitConversion" Schema="charlees" />
      </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="Wombat.Commerce.Data" Alias="Self" xmlns:annotation="http://schemas.microsoft.com/ado/2009/02/edm/annotation"&gt;
        <EntityContainer Name="WombatEntities" annotation:LazyLoadingEnabled="true">

          <EntitySet Name="Products" EntityType="Wombat.Commerce.Data.Product" />

        </EntityContainer>

        <EntityType Name="Product">
          <Key>
            <PropertyRef Name="ProductID" />
          </Key>

          <Property Type="Decimal" Name="Price" Nullable="true" />

          <Property Type="Int32" Name="ProductID" Nullable="false" annotation:StoreGeneratedPattern="Identity" />
          <Property Type="String" Name="Name" />
          <Property Type="String" Name="ShortDescription" />
          <Property Type="String" Name="Sku" />
        </EntityType>
      </Schema>
    </edmx:ConceptualModels>
    <!-- C-S mapping content -->
    <edmx:Mappings>
      <Mapping xmlns="http://schemas.microsoft.com/ado/2008/09/mapping/cs" Space="C-S">
        <Alias Key="Model" Value="Wombat" />
        <Alias Key="Target" Value="Wombat.Store" />
        <EntityContainerMapping CdmEntityContainer="WombatEntities" StorageEntityContainer="WombatStoreContainer">
          <EntitySetMapping Name="Products">
            <EntityTypeMapping TypeName="Wombat.Commerce.Data.Product">
              <MappingFragment StoreEntitySet="product">
                <ScalarProperty Name="Description" ColumnName="Description" />
                <ScalarProperty Name="Name" ColumnName="Name" />
                <ScalarProperty Name="ProductID" ColumnName="ProductID" />
                <ScalarProperty Name="Price" ColumnName="Price" />

              </MappingFragment>
            </EntityTypeMapping>
          </EntitySetMapping>

        </EntityContainerMapping>
      </Mapping>
    </edmx:Mappings>
  </edmx:Runtime>


</edmx:Edmx>
+1  A: 

This appears to be a similar problem to yours.

http://social.msdn.microsoft.com/Forums/en-US/adodotnetentityframework/thread/1e40d986-4e5c-4da1-a526-b8cf472fb4d5

You'll have to make a wrapper property of type Int64.

Jerome