Cant Update Decimal String in Entity Frameworking using mySql

I have been working on this issue 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;} } 

Error code

 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 internal exception error that I get is

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

The error does not work if you stop the update in the price column.

These are object mappings

  <?xml version="1.0" encoding="utf-8"?> <edmx:Edmx Version="2.0" xmlns:edmx="http://schemas.microsoft.com/ado/2008/10/edmx"> <!-- 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"> <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"> <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> <!-- CS mapping content --> <edmx:Mappings> <Mapping xmlns="http://schemas.microsoft.com/ado/2008/09/mapping/cs" Space="CS"> <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> 
+4
source share
1 answer

This seems like a similar issue for you.

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

You will need to make a shell property of type Int64.

+2
source

All Articles