Bug #61672 Mapping of BIT(1) columns returned by a stored procedure uses a wrong type.
Submitted: 28 Jun 2011 13:45 Modified: 30 Jun 2011 18:28
Reporter: Roman Ovseitsev Email Updates:
Status: Not a Bug Impact on me:
None 
Category:Connector / NET Severity:S2 (Serious)
Version:6.3.7 OS:Windows (Windows 7 32bit)
Assigned to: Julio Casal CPU Architecture:Any

[28 Jun 2011 13:45] Roman Ovseitsev
Description:
During the mapping of Boolean properties they are mistakenly use type of the property defined just before it in the ComplexType definition (String type of client_name property in the example below). 
6.3.5 didn't had this issue. I haven't tested it on 6.3.6.

How to repeat:
Database structure:
=======================================================

CREATE TABLE `campaign` (
	`id` INT(10) NOT NULL AUTO_INCREMENT,
	`bit_field` BIT(1) NOT NULL,
	PRIMARY KEY (`id`)
)
COLLATE='utf8_general_ci'
ENGINE=InnoDB
AUTO_INCREMENT=14;

INSERT INTO `campaign` VALUES (6, b'0'),(7, b'1'),(8, b'0'),(9, b'0');

DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `sp_campaigns`()
	LANGUAGE SQL
	NOT DETERMINISTIC
	CONTAINS SQL
	SQL SECURITY DEFINER
	COMMENT ''
BEGIN
SELECT c.bit_field, 'test' as client_name FROM campaign as c;
END;;
DELIMITER ;

EDMX:
=======================================================
<?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="Model.Store" Alias="Self" Provider="MySql.Data.MySqlClient" ProviderManifestToken="5.1" xmlns:store="http://schemas.microsoft.com/ado/2007/12/edm/EntityStoreSchemaGenerator" xmlns="http://schemas.microsoft.com/ado/2009/02/edm/ssdl">
        <EntityContainer Name="ModelStoreContainer" />
        <Function Name="sp_campaigns" Aggregate="false" BuiltIn="false" NiladicFunction="false" IsComposable="false" ParameterTypeSemantics="AllowImplicitConversion" Schema="gap_exp" />
      </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="Model" Alias="Self" xmlns:annotation="http://schemas.microsoft.com/ado/2009/02/edm/annotation">
        <EntityContainer Name="ModelContainer" annotation:LazyLoadingEnabled="true">
          <FunctionImport Name="sp_campaigns" ReturnType="Collection(Model.sp_test_Result1)" />
        </EntityContainer>
        <ComplexType Name="sp_test_Result1" >
          <Property Type="String" Name="client_name" Nullable="false" />
          <Property Type="Boolean" Name="bit_field" Nullable="false" />
        </ComplexType>
      </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="Model" />
        <Alias Key="Target" Value="Model.Store" />
        <EntityContainerMapping CdmEntityContainer="ModelContainer" StorageEntityContainer="ModelStoreContainer">
          <FunctionImportMapping FunctionImportName="sp_campaigns" FunctionName="Model.Store.sp_campaigns">
          <ResultMapping>
              <ComplexTypeMapping TypeName="Model.sp_test_Result1">
                <ScalarProperty Name="client_name" ColumnName="client_name" />
                <ScalarProperty Name="bit_field" ColumnName="bit_field" />
              </ComplexTypeMapping>
            </ResultMapping>
          </FunctionImportMapping>
        </EntityContainerMapping>
      </Mapping>
    </edmx:Mappings>
  </edmx:Runtime>
  <!-- EF Designer content (DO NOT EDIT MANUALLY BELOW HERE) -->
  <edmx:Designer xmlns="http://schemas.microsoft.com/ado/2008/10/edmx">
    <edmx:Connection>
      <DesignerInfoPropertySet>
        <DesignerProperty Name="MetadataArtifactProcessing" Value="EmbedInOutputAssembly" />
      </DesignerInfoPropertySet>
    </edmx:Connection>
    <edmx:Options>
      <DesignerInfoPropertySet>
        <DesignerProperty Name="ValidateOnBuild" Value="true" />
        <DesignerProperty Name="EnablePluralization" Value="True" />
        <DesignerProperty Name="IncludeForeignKeysInModel" Value="True" />
      </DesignerInfoPropertySet>
    </edmx:Options>
    <!-- Diagram content (shape and connector positions) -->
    <edmx:Diagrams>
      <Diagram Name="Model" />
    </edmx:Diagrams>
  </edmx:Designer>
</edmx:Edmx>

Code:
==================================================================
var octx = new ModelContainer();
var result = octx.ExecuteFunction<sp_test_Result1>("sp_campaigns").ToList();

The above code throws exception:	
The 'bit_field' property on 'sp_test_Result1' could not be set to a 'String' value. You must set this property to a non-null value of type 'Boolean'.
[30 Jun 2011 18:28] Julio Casal
Thank you for taking the time to write to us, but this is not a bug. 

The order of the parameters in your stored procedure and in your EDMX file does not match. In the procedure, the bit goes first and in the EDMX the String goes first. To follow the procedure order, the Boolean property should go first in the EDMX. Please fix the order of the parameters either in the procedure or in the EDMX file to get rid of the exception.