File Fuzzing with Peach - fuzzing

I am a beginner in file fuzzing.I want to fuzz Adrenalin Player 2.2.5.3 with peach 3 and during compile got a problem. when I enter this command c:\peach\peach.exe wav.xml receive this error: unable to locate test named "Default".
and here is my code in xml :
<!-- Defines the common wave chunk -->
<DataModel name="Chunk">
<String name="ID" length="4" padCharacter=" " />
<Number name="Size" size="32" >
<Relation type="size" of="Data" />
</Number>
<Blob name="Data" />
<Padding alignment="16" />
</DataModel>
<DataModel name="ChunkData" ref="Chunk">
<String name="ID" value="data" token="true"/>
</DataModel>
<DataModel name="ChunkFact" ref="Chunk">
<String name="ID" value="fact" token="true"/>
<Block name="Data">
<Number size="32" />
<Blob/>
</Block>
</DataModel>
<DataModel name="ChunkSint" ref="Chunk">
<String name="ID" value="sInt" token="true"/>
<Block name="Data">
<Number size="32" />
</Block>
</DataModel>
<DataModel name="ChunkWavl" ref="Chunk">
<String name="ID" value="wavl" token="true"/>
<Block name="Data">
<Block name="ArrayOfChunks" maxOccurs="3000">
<Block ref="ChunkSint"/>
<Block ref="ChunkData" />
</Block>
</Block>
</DataModel>
<DataModel name="ChunkCue" ref="Chunk">
<String name="ID" value="cue " token="true"/>
<Block name="Data">
<Block name="ArrayOfCues" maxOccurs="3000">
<String length="4" />
<Number size="32" />
<String length="4" />
<Number size="32" />
<Number size="32" />
<Number size="32" />
</Block>
</Block>
</DataModel>
<DataModel name="ChunkFmt" ref="Chunk">
<String name="ID" value="fmt " token="true"/>
<Block name="Data">
<Number name="CompressionCode" size="16" />
<Number name="NumberOfChannels" size="16" />
<Number name="SampleRate" size="32" />
<Number name="AverageBytesPerSecond" size="32" />
<Number name="BlockAlign" size="16" />
<Number name="SignificantBitsPerSample" size="16" />
<Number name="ExtraFormatBytes" size="16" />
<Blob name="ExtraData" />
</Block>
</DataModel>
<DataModel name="ChunkPlst" ref="Chunk">
<String name="ID" value="plst" token="true"/>
<Block name="Data">
<Number name="NumberOfSegments" size="32" >
<Relation type="count" of="ArrayOfSegments"/>
</Number>
<Block name="ArrayOfSegments" maxOccurs="3000">
<String length="4" />
<Number size="32" />
<Number size="32" />
</Block>
</Block>
</DataModel>
<DataModel name="ChunkLtxt" ref="Chunk">
<String name="ID" value="ltxt" token="true"/>
<Block name="Data">
<Number size="32" />
<Number size="32" />
<Number size="32" />
<Number size="16" />
<Number size="16" />
<Number size="16" />
<Number size="16" />
<String nullTerminated="true" />
</Block>
</DataModel>
<DataModel name="ChunkSmpl" ref="Chunk">
<String name="ID" value="smpl" token="true"/>
<Block name="Data">
<Number size="32" />
<Number size="32" />
<Number size="32" />
<Number size="32" />
<Number size="32" />
<Number size="32" />
<Number size="32" />
<Number size="32" />
<Number size="32" />
<Block maxOccurs="3000">
<Number size="32" />
<Number size="32" />
<Number size="32" />
<Number size="32" />
<Number size="32" />
<Number size="32" />
</Block>
</Block>
</DataModel>
<DataModel name="ChunkInst" ref="Chunk">
<String name="ID" value="inst" token="true"/>
<Block name="Data">
<Number size="8"/>
<Number size="8"/>
<Number size="8"/>
<Number size="8"/>
<Number size="8"/>
<Number size="8"/>
<Number size="8"/>
</Block>
</DataModel>
<!-- Defines the format of a WAV file -->
<DataModel name="Wav">
<!-- wave header -->
<String value="RIFF" token="true" />
<Number size="32" />
<String value="WAVE" token="true"/>
<Choice maxOccurs="30000">
<Block ref="ChunkFmt"/>
<Block ref="ChunkData"/>
<Block ref="ChunkFact"/>
<Block ref="ChunkSint"/>
<Block ref="ChunkWavl"/>
<Block ref="ChunkCue"/>
<Block ref="ChunkPlst"/>
<Block ref="ChunkLtxt"/>
<Block ref="ChunkSmpl"/>
<Block ref="ChunkInst"/>
<Block ref="Chunk"/>
</Choice>
</DataModel>
<!-- This is our simple wave state model -->
<StateModel name="TheState" initialState="Initial">
<State name="Initial">
<!-- Write out our wave file -->
<Action type="output">
<DataModel ref="Wav"/>
<!-- This is our sample file to read in -->
<Data fileName="sample.wav"/>
</Action>
<Action type="close"/>
<!-- Launch the target process -->
<Action type="call" method="StartMPlayer" publisher="Peach.Agent" />
</State>
</StateModel>
<Agent name="WinAgent">
<Monitor class="WindowsDebugger">
<!-- The command line to run. Notice the filename provided matched up
to what is provided below in the Publisher configuration -->
<Param name="CommandLine" value="c:\\Program Files (x86)\\adrenalin\\play.exe fuzzed.wav" />
<!-- This parameter will cause the debugger to wait for an action-call in
the state model with a method="StartMPlayer" before running
program.
-->
<Param name="StartOnCall" value="StartMPlayer" />
<!-- This parameter will cause the monitor to terminate the process
once the CPU usage reaches zero.
-->
<Param name="CpuKill" value="true"/>
</Monitor>
<!-- Enable heap debugging on our process as well. -->
<Monitor class="PageHeap">
<Param name="Executable" value="c:\\Program Files (x86)\\adrenalin\\play.exe"/>
</Monitor>
</Agent>
<Agent name="LinAgent">
<!-- Register for core file notifications. -->
<Monitor class="LinuxCrashMonitor"/>
<Monitor class="Process">
<!-- The executable to run. -->
<Param name="Executable" value="mplayer"/>
<!-- This parameter will cause the monitor to wait for an action-call in
the state model with a method="StartMPlayer" before running
program.
-->
<Param name="StartOnCall" value="StartMPlayer"/>
<!-- The program arguments. Notice the filename provided matched up
to what is provided below in the Publisher configuration -->
<Param name="Arguments" value="fuzzed.wav"/>
<!-- This parameter will cause the monitor to terminate the process
once the CPU usage reaches zero.
-->
<Param name="CpuKill" value="true"/>
</Monitor>
</Agent>
<Agent name="OsxAgent">
<Monitor class="CrashWrangler">
<!-- The executable to run. -->
<Param name="Command" value="mplayer" />
<!-- The program arguments. Notice the filename provided matched up
to what is provided below in the Publisher configuration -->
<Param name="Arguments" value="fuzzed.wav" />
<!-- Do not use debug malloc. -->
<Param name="UseDebugMalloc" value="false" />
<!-- Treat read access violations as exploitable. -->
<Param name="ExploitableReads" value="true" />
<!-- Path to Crash Wrangler Execution Handler program. -->
<Param name="ExecHandler" value="/usr/local/bin/exc_handler" />
<!-- This parameter will cause the monitor to wait for an action-call in
the state model with a method="StartMPlayer" before running
program.
-->
<Param name="StartOnCall" value="StartMPlayer" />
</Monitor>
</Agent>
<Test name="Default">
<Agent ref="WinAgent" platform="windows"/>
<Agent ref="LinAgent" platform="linux"/>
<Agent ref="OsxAgent" platform="osx"/>
<StateModel ref="TheState"/>
<Publisher class="File">
<Param name="FileName" value="fuzzed.wav"/>
</Publisher>
<Logger class="Filesystem">
<Param name="Path" value="logs" />
</Logger>
</Test>

When you use the Peach Framework, your pit files(the xml file you have included) must be completed encapsulated by a <Peach>.........</Peach> tag. Try this and see what happens!

Related

Unsure how to fix the error in the Azure Devops Migration Tool for very old TFS collections

We've been asked to migrate some very old legacy projects (i.e. from TFS 2010 days) onto Azure Devops Services. These very old projects have almost nothing in their Process Configuration and only have one error line in the logs from the migration tool for all project types (Scrum, Agile, Basic etc...).
[Info #15:27:48.998] === Found 1 error(s) when compared against process TFS 2019 Update 1 Scrum ===
[Error #15:27:48.998] Custom processConfiguration typeField count '0' is different than system '8'.
[Info #15:27:48.998] === End of error(s) when compared against process TFS 2019 Update 1 Scrum ===
When looking at their Process Configuation it is only a few lines:
<?xml version="1.0" encoding="utf-16"?>
<ProjectProcessConfiguration>
<RequirementBacklog workItemCountLimit="1000">
<AddPanel />
</RequirementBacklog>
<TaskBacklog workItemCountLimit="1000">
<AddPanel />
</TaskBacklog>
<Properties>
<Property name="BugsBehavior" value="Off" />
</Properties>
</ProjectProcessConfiguration>
The only project that has no errors was a project added much later on TFS 2015:
<?xml version="1.0" encoding="utf-16"?>
<ProjectProcessConfiguration>
<BugWorkItems category="Microsoft.BugCategory" pluralName="Bugs" singularName="Bug">
<States>
<State type="Proposed" value="New" />
<State type="InProgress" value="Active" />
<State type="Complete" value="Closed" />
<State type="Resolved" value="Resolved" />
</States>
</BugWorkItems>
<FeedbackRequestWorkItems category="Microsoft.FeedbackRequestCategory" pluralName="Feedback Requests" singularName="Feedback Request">
<States>
<State type="InProgress" value="Active" />
<State type="Complete" value="Closed" />
</States>
</FeedbackRequestWorkItems>
<FeedbackResponseWorkItems category="Microsoft.FeedbackResponseCategory" pluralName="Feedback Responses" singularName="Feedback Response">
<States>
<State type="InProgress" value="Active" />
<State type="Complete" value="Closed" />
</States>
</FeedbackResponseWorkItems>
<PortfolioBacklogs>
<PortfolioBacklog category="Microsoft.EpicCategory" pluralName="Epics" singularName="Epic" workItemCountLimit="1000">
<AddPanel>
<Fields>
<Field refname="System.Title" />
</Fields>
</AddPanel>
<Columns>
<Column width="100" refname="System.WorkItemType" />
<Column width="400" refname="System.Title" />
<Column width="100" refname="System.State" />
<Column width="50" refname="Microsoft.VSTS.Scheduling.Effort" />
<Column width="50" refname="Microsoft.VSTS.Common.BusinessValue" />
<Column width="100" refname="Microsoft.VSTS.Common.ValueArea" />
<Column width="200" refname="System.Tags" />
</Columns>
<States>
<State type="Proposed" value="New" />
<State type="InProgress" value="Active" />
<State type="InProgress" value="Resolved" />
<State type="Complete" value="Closed" />
</States>
</PortfolioBacklog>
<PortfolioBacklog category="Microsoft.FeatureCategory" parent="Microsoft.EpicCategory" pluralName="Features" singularName="Feature" workItemCountLimit="1000">
<AddPanel>
<Fields>
<Field refname="System.Title" />
</Fields>
</AddPanel>
<Columns>
<Column width="100" refname="System.WorkItemType" />
<Column width="400" refname="System.Title" />
<Column width="100" refname="System.State" />
<Column width="50" refname="Microsoft.VSTS.Scheduling.Effort" />
<Column width="50" refname="Microsoft.VSTS.Common.BusinessValue" />
<Column width="100" refname="Microsoft.VSTS.Common.ValueArea" />
<Column width="200" refname="System.Tags" />
</Columns>
<States>
<State type="Proposed" value="New" />
<State type="InProgress" value="Active" />
<State type="InProgress" value="Resolved" />
<State type="Complete" value="Closed" />
</States>
</PortfolioBacklog>
</PortfolioBacklogs>
<RequirementBacklog category="Microsoft.RequirementCategory" parent="Microsoft.FeatureCategory" pluralName="Stories" singularName="User Story" workItemCountLimit="1000">
<AddPanel>
<Fields>
<Field refname="System.Title" />
</Fields>
</AddPanel>
<Columns>
<Column width="100" refname="System.WorkItemType" />
<Column width="400" refname="System.Title" />
<Column width="100" refname="System.State" />
<Column width="50" refname="Microsoft.VSTS.Scheduling.StoryPoints" />
<Column width="100" refname="Microsoft.VSTS.Common.ValueArea" />
<Column width="200" refname="System.IterationPath" />
<Column width="200" refname="System.Tags" />
</Columns>
<States>
<State type="Proposed" value="New" />
<State type="InProgress" value="Active" />
<State type="InProgress" value="Resolved" />
<State type="Complete" value="Closed" />
</States>
</RequirementBacklog>
<TaskBacklog category="Microsoft.TaskCategory" parent="Microsoft.RequirementCategory" pluralName="Tasks" singularName="Task" workItemCountLimit="1000">
<AddPanel>
<Fields>
<Field refname="System.Title" />
</Fields>
</AddPanel>
<Columns>
<Column width="400" refname="System.Title" />
<Column width="100" refname="System.State" />
<Column width="100" refname="System.AssignedTo" />
<Column width="50" refname="Microsoft.VSTS.Scheduling.RemainingWork" />
</Columns>
<States>
<State type="Proposed" value="New" />
<State type="InProgress" value="Active" />
<State type="Complete" value="Closed" />
</States>
</TaskBacklog>
<TypeFields>
<TypeField refname="Microsoft.VSTS.Common.Activity" type="Activity" />
<TypeField refname="Microsoft.VSTS.Common.StackRank" type="Order" />
<TypeField refname="Microsoft.VSTS.Feedback.ApplicationLaunchInstructions" type="ApplicationLaunchInstructions" />
<TypeField refname="Microsoft.VSTS.Feedback.ApplicationStartInformation" type="ApplicationStartInformation" />
<TypeField refname="Microsoft.VSTS.Feedback.ApplicationType" type="ApplicationType">
<TypeFieldValues>
<TypeFieldValue type="ClientApp" value="Client application" />
<TypeFieldValue type="RemoteMachine" value="Remote machine" />
<TypeFieldValue type="WebApp" value="Web application" />
</TypeFieldValues>
</TypeField>
<TypeField format="{0} h" refname="Microsoft.VSTS.Scheduling.RemainingWork" type="RemainingWork" />
<TypeField refname="Microsoft.VSTS.Scheduling.StoryPoints" type="Effort" />
<TypeField refname="System.AreaPath" type="Team" />
</TypeFields>
<Weekends>
<DayOfWeek>Sunday</DayOfWeek>
<DayOfWeek>Saturday</DayOfWeek>
</Weekends>
<Properties>
<Property name="HiddenBacklogs" value="Microsoft.EpicCategory" />
<Property name="BugsBehavior" value="AsTasks" />
</Properties>
<WorkItemColors>
<WorkItemColor primary="FFCC293D" secondary="FFFAEAE5" name="Bug" />
<WorkItemColor primary="FFFF9D00" secondary="FFFCEECF" name="Code Review Request" />
<WorkItemColor primary="FFFF9D00" secondary="FFFCEECF" name="Code Review Response" />
<WorkItemColor primary="FFFF7B00" secondary="FFFFD7B5" name="Epic" />
<WorkItemColor primary="FF773B93" secondary="FFEEE2F2" name="Feature" />
<WorkItemColor primary="FFFF9D00" secondary="FFFCEECF" name="Feedback Request" />
<WorkItemColor primary="FFFF9D00" secondary="FFFCEECF" name="Feedback Response" />
<WorkItemColor primary="FFFF9D00" secondary="FFFCEECF" name="Issue" />
<WorkItemColor primary="FFFF9D00" secondary="FFFCEECF" name="Shared Parameter" />
<WorkItemColor primary="FFFF9D00" secondary="FFFCEECF" name="Shared Steps" />
<WorkItemColor primary="FFF2CB1D" secondary="FFF6F5D2" name="Task" />
<WorkItemColor primary="FFFF9D00" secondary="FFFCEECF" name="Test Case" />
<WorkItemColor primary="FFFF9D00" secondary="FFFCEECF" name="Test Plan" />
<WorkItemColor primary="FFFF9D00" secondary="FFFCEECF" name="Test Suite" />
<WorkItemColor primary="FF009CCC" secondary="FFD6ECF2" name="User Story" />
</WorkItemColors>
</ProjectProcessConfiguration>
Anyone know of a easy way to fix the older projects? We want to import the code with changeset histories into Azure Devop Services and none of them have actually have work items (was managed externally on JIRA), build and release configs etc... We just want to get them onto the cloud to retire the legacy onpremise TFS servers (which are now running Azure Devops Server 2020.1.1 as per the migration suggestions).
Thanks for any help.
Edit: we're using TFS Team Project Manager from Jelle Druyts to help do some of the analysis, and am wondering if we can use the Transform function under Process Configuration to import the working projects config into the other projects.
Mark.
Sorry for the late reply on this. Since we didn't need to preserve templates and work items/ task history, we ended up abandoning full migrations. Ended up using the git-tfs (https://git-tfs.com/) tool to convert the TFS projects to a local git repository, then attaching that to a new Azure git project. Preserved all our history which was great.

Issue in EF, mapping fragment,no default value and is not nullable

I am developing MVC 3 Applicaiton.
I have Model first approch.
I have Company Entity(Abstract).
Lead and Customer is inherited from the company entity.
When I tried to validate the model, Its gives an errror.
Error 41 Error 3023: Problem in mapping fragments starting at line
70:Column Companies.Status in table Companies must be mapped: It has
no default value and is not nullable.
Here is the mapping of tables.
And Here is the EDMX code in HTML View.
<?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="Model1.Store" Alias="Self" Provider="System.Data.SqlClient" ProviderManifestToken="2008" xmlns="http://schemas.microsoft.com/ado/2009/02/edm/ssdl" xmlns:store="http://schemas.microsoft.com/ado/2007/12/edm/EntityStoreSchemaGenerator">
<EntityContainer Name="Model1StoreContainer">
<EntitySet Name="Companies" EntityType="Model1.Store.Companies" store:Type="Tables" Schema="dbo" />
</EntityContainer>
<EntityType Name="Companies">
<Key>
<PropertyRef Name="Id" />
</Key>
<Property Name="Id" Type="int" StoreGeneratedPattern="Identity" Nullable="false" />
<Property Name="Name" Type="nvarchar(max)" Nullable="false" />
<Property Name="Status" Type="nvarchar(max)" Nullable="false" />
<Property Name="__Disc__" Type="nvarchar" MaxLength="Max" Nullable="false" />
</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="Model1" Alias="Self" xmlns:annotation="http://schemas.microsoft.com/ado/2009/02/edm/annotation">
<EntityContainer Name="Model1Container" annotation:LazyLoadingEnabled="true">
<EntitySet Name="Companies" EntityType="Model1.Company" />
</EntityContainer>
<EntityType Name="Company" Abstract="true">
<Key>
<PropertyRef Name="Id" />
</Key>
<Property Type="Int32" Name="Id" Nullable="false" annotation:StoreGeneratedPattern="Identity" />
<Property Type="String" Name="Name" Nullable="false" />
</EntityType>
<EntityType Name="Lead" BaseType="Model1.Company" >
<Property Type="String" Name="Status" Nullable="false" />
</EntityType>
</Schema>
</edmx:ConceptualModels>
<!-- C-S mapping content -->
<edmx:Mappings>
<Mapping Space="C-S" xmlns="http://schemas.microsoft.com/ado/2008/09/mapping/cs">
<EntityContainerMapping StorageEntityContainer="Model1StoreContainer" CdmEntityContainer="Model1Container">
<EntitySetMapping Name="Companies">
<EntityTypeMapping TypeName="IsTypeOf(Model1.Company)">
<MappingFragment StoreEntitySet="Companies">
<ScalarProperty Name="Id" ColumnName="Id" />
<ScalarProperty Name="Name" ColumnName="Name" />
<Condition ColumnName="__Disc__" Value="Company" />
</MappingFragment>
</EntityTypeMapping>
<EntityTypeMapping TypeName="Model1.Lead">
<MappingFragment StoreEntitySet="Companies">
<ScalarProperty Name="Id" ColumnName="Id" />
<ScalarProperty Name="Name" ColumnName="Name" />
<ScalarProperty Name="Status" ColumnName="Status" />
<Condition ColumnName="__Disc__" Value="Lead" />
</MappingFragment>
</EntityTypeMapping>
</EntitySetMapping>
</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="DatabaseGenerationWorkflow" Value="$(VSEFTools)\DBGen\Generate T-SQL Via T4 (TPH).xaml" />
</DesignerInfoPropertySet>
</edmx:Options>
<!-- Diagram content (shape and connector positions) -->
<edmx:Diagrams>
<Diagram Name="Model1" >
<EntityTypeShape EntityType="Model1.Company" Width="1.5" PointX="2.375" PointY="0.875" Height="1.2636116536458335" />
<EntityTypeShape EntityType="Model1.Lead" Width="1.5" PointX="3.375" PointY="2.625" Height="1.0992643229166665" />
<InheritanceConnector EntityType="Model1.Lead" >
<ConnectorPoint PointX="3.125" PointY="2.1386116536458335" />
<ConnectorPoint PointX="3.125" PointY="2.325" />
<ConnectorPoint PointX="4.125" PointY="2.325" />
<ConnectorPoint PointX="4.125" PointY="2.625" />
</InheritanceConnector>
</Diagram>
</edmx:Diagrams>
</edmx:Designer>
</edmx:Edmx>
Whats is the issue ?
Put the DefaultValue attribute on the SSDL Status property. It would look like this (I used the empty string):
<Property Name="Status" Type="nvarchar(max)" Nullable="false" DefaultValue=""/>
Since the base entity is abstract you won't be able to create entities of this type so this DefaultValue will not really be used but it should make EF stop complaining.
In your storage model, the Companies.Status column doesn't allow null values.
Since all entities that inherit from Company except the Lead entity will not have the Status property set, you need to either allow null in the Companies.Status column or set a default value to use for the other entities.

Entity framework stored procedure mapping results not unique entities

I have a problem where I've mapped a stored procedure named sp_getMyEntity, which takes in one parameter called Id and then maps the results to a custom entity called MyEntity
I'm using mock data to illustrate the point. When I run the stored procedure with an id of 1, I get two distinct results back from the database:
exec [dbo].[sp_getMyEntity] #Id=1
Results:
ID - AddressId
1 - 6
1 - 3
When querying the ObjectContext using LINQ, I get 2 MyEntity's back but the AddressId for both of them is 6, not 6 and 3 respectively. Here is my call using LINQ:
Entities context = new Entities();
var entities = from s in context.GetMyEntity(1)
select s;
return entities.ToList();
Here is the EDMX xml:
<edmx:Edmx Version="1.0" xmlns:edmx="http://schemas.microsoft.com/ado/2007/06/edmx">
<!-- EF Runtime content -->
<edmx:Runtime>
<!-- SSDL content -->
<edmx:StorageModels>
<Schema Namespace="MyProjectModel.Store" Alias="Self" Provider="System.Data.SqlClient" ProviderManifestToken="2008" xmlns:store="http://schemas.microsoft.com/ado/2007/12/edm/EntityStoreSchemaGenerator" xmlns="http://schemas.microsoft.com/ado/2006/04/edm/ssdl">
<EntityContainer Name="MyProjectModelStoreContainer">
<EntitySet Name="MyEntitySet" EntityType="MyProjectModel.Store.MyEntity" />
</EntityContainer>
<Function Name="sp_getMyEntity" Aggregate="false" BuiltIn="false" NiladicFunction="false" IsComposable="false" ParameterTypeSemantics="AllowImplicitConversion" Schema="dbo">
<Parameter Name="Id" Type="int" Mode="In" />
</Function>
<EntityType Name="MyEntity">
<Key>
<PropertyRef Name="Id" />
</Key>
<Property Name="Id" Type="int" Nullable="false" />
<Property Name="AddressId" Type="int" Nullable="true" />
</EntityType>
</Schema>
</edmx:StorageModels>
<!-- CSDL content -->
<edmx:ConceptualModels>
<Schema Namespace="MyProjectModel" Alias="Self" xmlns="http://schemas.microsoft.com/ado/2006/04/edm">
<EntityContainer Name="MyProjectViewEntities" >
<EntitySet Name="MyEntitySet" EntityType="MyProjectModel.MyEntity" />
<FunctionImport Name="GetMyEntity" EntitySet="MyEntitySet" ReturnType="Collection(MyProjectModel.MyEntity)">
<Parameter Name="Id" Mode="In" Type="Int32" />
</FunctionImport>
</EntityContainer>
<EntityType Name="MyEntity">
<Key>
<PropertyRef Name="Id" />
</Key>
<Property Name="Id" Type="Int32" Nullable="false" />
<Property Name="AddressId" Type="Int32" Nullable="true" />
</EntityType>
</Schema>
</edmx:ConceptualModels>
<!-- C-S mapping content -->
<edmx:Mappings>
<Mapping Space="C-S" xmlns="urn:schemas-microsoft-com:windows:storage:mapping:CS">
<EntityContainerMapping StorageEntityContainer="MyProjectModelStoreContainer" CdmEntityContainer="MyProjectViewEntities" >
<FunctionImportMapping FunctionImportName="GetMyEntity" FunctionName="MyProjectModel.Store.sp_getMyEntity" />
<EntitySetMapping Name="MyEntitySet">
<EntityTypeMapping TypeName="IsTypeOf(MyProjectModel.MyEntity)">
<MappingFragment StoreEntitySet="MyEntitySet">
<ScalarProperty Name="AddressId" ColumnName="AddressId" />
<ScalarProperty Name="Id" ColumnName="Id" />
</MappingFragment>
</EntityTypeMapping>
</EntitySetMapping>
</EntityContainerMapping>
</Mapping>
</edmx:Mappings>
</edmx:Runtime>
<!-- EF Designer content (DO NOT EDIT MANUALLY BELOW HERE) -->
<edmx:Designer xmlns="http://schemas.microsoft.com/ado/2007/06/edmx">
<edmx:Connection>
<DesignerInfoPropertySet>
<DesignerProperty Name="MetadataArtifactProcessing" Value="EmbedInOutputAssembly" />
</DesignerInfoPropertySet>
</edmx:Connection>
<edmx:Options>
<DesignerInfoPropertySet>
<DesignerProperty Name="ValidateOnBuild" Value="true" />
</DesignerInfoPropertySet>
</edmx:Options>
<!-- Diagram content (shape and connector positions) -->
<edmx:Diagrams>
<Diagram Name="MyProjectModel" ZoomLevel="100" >
<EntityTypeShape EntityType="MyProjectModel.MyEntity" Width="1.5" PointX="5.25" PointY="0.5" Height="7.8375048828125" />
<EntityTypeShape EntityType="MyProjectModel.MyEntity" Width="1.5" PointX="5.5" PointY="1.375" Height="1.2636116536458335" /></Diagram></edmx:Diagrams>
</edmx:Designer>
</edmx:Edmx>
Any ideas why the MyEntity's are not unique?
Because the SP column which your SSDL identifies as the key is not a unique column. You cannot have a "key" with duplicate values.
As Craig stated above my Key property was not unique, so I ended up changing the SQL to look at follows:
SELECT
ROW_NUMBER() OVER(ORDER BY Id) AS KeyId
, Id
, AddressId
FROM
MyTable
WHERE
Id = #Id
Then the EDMX xml looks as follows, notice the new key is a bigint and Int64:
<edmx:Edmx Version="1.0" xmlns:edmx="http://schemas.microsoft.com/ado/2007/06/edmx">
<!-- EF Runtime content -->
<edmx:Runtime>
<!-- SSDL content -->
<edmx:StorageModels>
<Schema Namespace="MyProjectModel.Store" Alias="Self" Provider="System.Data.SqlClient" ProviderManifestToken="2008" xmlns:store="http://schemas.microsoft.com/ado/2007/12/edm/EntityStoreSchemaGenerator" xmlns="http://schemas.microsoft.com/ado/2006/04/edm/ssdl">
<EntityContainer Name="MyProjectModelStoreContainer">
<EntitySet Name="MyEntitySet" EntityType="MyProjectModel.Store.MyEntity" />
</EntityContainer>
<Function Name="sp_getMyEntity" Aggregate="false" BuiltIn="false" NiladicFunction="false" IsComposable="false" ParameterTypeSemantics="AllowImplicitConversion" Schema="dbo">
<Parameter Name="Id" Type="int" Mode="In" />
</Function>
<EntityType Name="MyEntity">
<Key>
<PropertyRef Name="KeyId" />
</Key>
<Property Name="KeyId" Type="bigint" Nullable="false" />
<Property Name="Id" Type="int" Nullable="false" />
<Property Name="AddressId" Type="int" Nullable="true" />
</EntityType>
</Schema>
</edmx:StorageModels>
<!-- CSDL content -->
<edmx:ConceptualModels>
<Schema Namespace="MyProjectModel" Alias="Self" xmlns="http://schemas.microsoft.com/ado/2006/04/edm">
<EntityContainer Name="MyProjectViewEntities" >
<EntitySet Name="MyEntitySet" EntityType="MyProjectModel.MyEntity" />
<FunctionImport Name="GetMyEntity" EntitySet="MyEntitySet" ReturnType="Collection(MyProjectModel.MyEntity)">
<Parameter Name="Id" Mode="In" Type="Int32" />
</FunctionImport>
</EntityContainer>
<EntityType Name="MyEntity">
<Key>
<PropertyRef Name="KeyId" />
</Key>
<Property Name="KeyId" Type="Int64" Nullable="false" />
<Property Name="Id" Type="Int32" Nullable="false" />
<Property Name="AddressId" Type="Int32" Nullable="true" />
</EntityType>
</Schema>
</edmx:ConceptualModels>
<!-- C-S mapping content -->
<edmx:Mappings>
<Mapping Space="C-S" xmlns="urn:schemas-microsoft-com:windows:storage:mapping:CS">
<EntityContainerMapping StorageEntityContainer="MyProjectModelStoreContainer" CdmEntityContainer="MyProjectViewEntities" >
<FunctionImportMapping FunctionImportName="GetMyEntity" FunctionName="MyProjectModel.Store.sp_getMyEntity" />
<EntitySetMapping Name="MyEntitySet">
<EntityTypeMapping TypeName="IsTypeOf(MyProjectModel.MyEntity)">
<MappingFragment StoreEntitySet="MyEntitySet">
<ScalarProperty Name="AddressId" ColumnName="AddressId" />
<ScalarProperty Name="Id" ColumnName="Id" />
<ScalarProperty Name="KeyId" ColumnName="KeyId" />
</MappingFragment>
</EntityTypeMapping>
</EntitySetMapping>
</EntityContainerMapping>
</Mapping>
</edmx:Mappings>
</edmx:Runtime>
<!-- EF Designer content (DO NOT EDIT MANUALLY BELOW HERE) -->
<edmx:Designer xmlns="http://schemas.microsoft.com/ado/2007/06/edmx">
<edmx:Connection>
<DesignerInfoPropertySet>
<DesignerProperty Name="MetadataArtifactProcessing" Value="EmbedInOutputAssembly" />
</DesignerInfoPropertySet>
</edmx:Connection>
<edmx:Options>
<DesignerInfoPropertySet>
<DesignerProperty Name="ValidateOnBuild" Value="true" />
</DesignerInfoPropertySet>
</edmx:Options>
<!-- Diagram content (shape and connector positions) -->
<edmx:Diagrams>
<Diagram Name="MyProjectModel" ZoomLevel="100" >
<EntityTypeShape EntityType="MyProjectModel.MyEntity" Width="1.5" PointX="5.25" PointY="0.5" Height="7.8375048828125" />
<EntityTypeShape EntityType="MyProjectModel.MyEntity" Width="1.5" PointX="5.5" PointY="1.375" Height="1.2636116536458335" /></Diagram></edmx:Diagrams>
</edmx:Designer>
</edmx:Edmx>

Entity Framework - inserting new entity via objectcontext does not use existing entity properties

I have an insert method on my repository like so:
public T Insert(T entity)
{
_ctx.AddObject(EntityName, entity);
_ctx.SaveChanges();
return entity;
}
If I execute the below code, the values assigned to my entity do not propagate to the SQL that is executed.
Category c = new Category();
c.Name = CLEARANCE;
c = categoryManager.Insert(c);
The SQL should be something like
INSERT INTO Category(Name) VALUES('Clearance')
Instead, the following SQL is being executed
insert [dbo].[Category]([Name])
values (null)
select [Id]
from [dbo].[Category]
where ##ROWCOUNT > 0 and [Id] = scope_identity()
I debugged the code right down to the AddObject method and verified that the Name property was set on the entity, but it doesn't reflect that in the SQL.
Can you see anything wrong with what I'm doing?
Updated with mapping xml
<?xml version="1.0" encoding="utf-8"?>
<edmx:Edmx Version="1.0" xmlns:edmx="http://schemas.microsoft.com/ado/2007/06/edmx">
<!-- EF Runtime content -->
<edmx:Runtime>
<!-- SSDL content -->
<edmx:StorageModels>
<Schema Namespace="ProductCatalogModel.Store" Alias="Self" Provider="System.Data.SqlClient" ProviderManifestToken="2008" xmlns:store="http://schemas.microsoft.com/ado/2007/12/edm/EntityStoreSchemaGenerator" xmlns="http://schemas.microsoft.com/ado/2006/04/edm/ssdl">
<EntityContainer Name="ProductCatalogModelStoreContainer">
<EntitySet Name="Category" EntityType="ProductCatalogModel.Store.Category" store:Type="Tables" Schema="dbo" />
<EntitySet Name="Product" EntityType="ProductCatalogModel.Store.Product" store:Type="Tables" Schema="dbo" />
<AssociationSet Name="FK_Product_Category" Association="ProductCatalogModel.Store.FK_Product_Category">
<End Role="Category" EntitySet="Category" />
<End Role="Product" EntitySet="Product" />
</AssociationSet>
</EntityContainer>
<EntityType Name="Category">
<Key>
<PropertyRef Name="Id" />
</Key>
<Property Name="Id" Type="int" Nullable="false" StoreGeneratedPattern="Identity" />
<Property Name="Name" Type="varchar" Nullable="false" MaxLength="50" />
</EntityType>
<EntityType Name="Product">
<Key>
<PropertyRef Name="Id" />
</Key>
<Property Name="Id" Type="int" Nullable="false" StoreGeneratedPattern="Identity" />
<Property Name="Name" Type="varchar" Nullable="false" MaxLength="50" />
<Property Name="CategoryId" Type="int" Nullable="false" />
</EntityType>
<Association Name="FK_Product_Category">
<End Role="Category" Type="ProductCatalogModel.Store.Category" Multiplicity="1" />
<End Role="Product" Type="ProductCatalogModel.Store.Product" Multiplicity="*" />
<ReferentialConstraint>
<Principal Role="Category">
<PropertyRef Name="Id" />
</Principal>
<Dependent Role="Product">
<PropertyRef Name="CategoryId" />
</Dependent>
</ReferentialConstraint>
</Association>
</Schema>
</edmx:StorageModels>
<!-- CSDL content -->
<edmx:ConceptualModels>
<Schema Namespace="ProductCatalogModel" Alias="Self" xmlns="http://schemas.microsoft.com/ado/2006/04/edm">
<EntityContainer Name="ProductCatalogEntities">
<EntitySet Name="Category" EntityType="ProductCatalogModel.Category" />
<EntitySet Name="Product" EntityType="ProductCatalogModel.Product" />
<AssociationSet Name="FK_Product_Category" Association="ProductCatalogModel.FK_Product_Category">
<End Role="Category" EntitySet="Category" />
<End Role="Product" EntitySet="Product" />
</AssociationSet>
</EntityContainer>
<EntityType Name="Category">
<Key>
<PropertyRef Name="Id" />
</Key>
<Property Name="Id" Type="Int32" Nullable="false" />
<Property Name="Name" Type="String" Nullable="false" MaxLength="50" Unicode="false" FixedLength="false" />
<NavigationProperty Name="Product" Relationship="ProductCatalogModel.FK_Product_Category" FromRole="Category" ToRole="Product" />
</EntityType>
<EntityType Name="Product" Abstract="false">
<Key>
<PropertyRef Name="Id" />
</Key>
<Property Name="Id" Type="Int32" Nullable="false" />
<Property Name="Name" Type="String" Nullable="false" MaxLength="50" Unicode="false" FixedLength="false" />
<NavigationProperty Name="Category" Relationship="ProductCatalogModel.FK_Product_Category" FromRole="Product" ToRole="Category" />
</EntityType>
<Association Name="FK_Product_Category">
<End Role="Category" Type="ProductCatalogModel.Category" Multiplicity="1" />
<End Role="Product" Type="ProductCatalogModel.Product" Multiplicity="*" />
</Association>
</Schema>
</edmx:ConceptualModels>
<!-- C-S mapping content -->
<edmx:Mappings>
<Mapping Space="C-S" xmlns="urn:schemas-microsoft-com:windows:storage:mapping:CS">
<EntityContainerMapping StorageEntityContainer="ProductCatalogModelStoreContainer" CdmEntityContainer="ProductCatalogEntities">
<EntitySetMapping Name="Category">
<EntityTypeMapping TypeName="IsTypeOf(ProductCatalogModel.Category)">
<MappingFragment StoreEntitySet="Category">
<ScalarProperty Name="Id" ColumnName="Id" />
<ScalarProperty Name="Name" ColumnName="Name" />
</MappingFragment>
</EntityTypeMapping>
</EntitySetMapping>
<EntitySetMapping Name="Product">
<EntityTypeMapping TypeName="IsTypeOf(ProductCatalogModel.Product)">
<MappingFragment StoreEntitySet="Product">
<ScalarProperty Name="Id" ColumnName="Id" />
<ScalarProperty Name="Name" ColumnName="Name" />
</MappingFragment>
</EntityTypeMapping>
</EntitySetMapping>
<AssociationSetMapping Name="FK_Product_Category" TypeName="ProductCatalogModel.FK_Product_Category" StoreEntitySet="Product">
<EndProperty Name="Category">
<ScalarProperty Name="Id" ColumnName="CategoryId" />
</EndProperty>
<EndProperty Name="Product">
<ScalarProperty Name="Id" ColumnName="Id" />
</EndProperty>
</AssociationSetMapping>
</EntityContainerMapping>
</Mapping>
</edmx:Mappings>
</edmx:Runtime>
<!-- EF Designer content (DO NOT EDIT MANUALLY BELOW HERE) -->
<edmx:Designer xmlns="http://schemas.microsoft.com/ado/2007/06/edmx">
<edmx:Connection>
<DesignerInfoPropertySet>
<DesignerProperty Name="MetadataArtifactProcessing" Value="EmbedInOutputAssembly" />
</DesignerInfoPropertySet>
</edmx:Connection>
<edmx:Options>
<DesignerInfoPropertySet>
<DesignerProperty Name="ValidateOnBuild" Value="true" />
</DesignerInfoPropertySet>
</edmx:Options>
<!-- Diagram content (shape and connector positions) -->
<edmx:Diagrams>
<Diagram Name="Model">
<EntityTypeShape EntityType="ProductCatalogModel.Category" Width="1.5" PointX="0.75" PointY="0.875" Height="1.427958984375" IsExpanded="true" />
<EntityTypeShape EntityType="ProductCatalogModel.Product" Width="1.5" PointX="3" PointY="0.875" Height="1.427958984375" IsExpanded="true" />
<AssociationConnector Association="ProductCatalogModel.FK_Product_Category" ManuallyRouted="false">
<ConnectorPoint PointX="2.25" PointY="1.5889794921875" />
<ConnectorPoint PointX="3" PointY="1.5889794921875" /></AssociationConnector>
</Diagram></edmx:Diagrams>
</edmx:Designer>
</edmx:Edmx>
I hate to say this, but all I did was mess with it for about an hour and now it works. I did not change a freaking thing. Thanks Microsoft for such a production ready technology.
Probably not related to this issue but a couple of things to think about with EntityFramework
The compilation is database specific. Problems can arise if you don't compile it against the database version you plan on using (eg. SQL Server 2005 vs 2000) - this can cause issues if your local DB is 2005 vs a test or production enviroment is 2000.
Making a small change to the edmx file, even something as small as moving an entity in the designer view will cause the database mapping files to recompile and can possibly fix issues related to mapping / etc.

How do I get the value of the Discriminator Column from an Entity Framework Entity

I've got a project in written in the EDM. Does anyone know how to get the value of the discriminator column from an entity in a TPH inheritance tree? I can't add the property to the entity. Is there any other way to get the value?
Thanks,
Roy
There is a simple way to solve the problem for the DBMS that suports updatable views.
You can simply create a view or a Defining Query having an additional discriminator column.
The original column should be mapped to the class property. In case when DBMS does not support the updatable views you can use Defining Query and then map stored procedures for Insert/Update/Delete operations.
Here is an example for Oracle database:
SQL:
CREATE TABLE TEST.TPH_TABLE (
ID NUMBER(9),
COLUMN_A VARCHAR2(20),
COLUMN_B VARCHAR2(20),
BASE_COLUMN VARCHAR2(20),
CONSTRAINT PK_TPH_TABLE PRIMARY KEY (ID)
);
EDMX:
<edmx:Edmx Version="1.0" xmlns:edmx="http://schemas.microsoft.com/ado/2007/06/edmx">
<!-- EF Runtime content -->
<edmx:Runtime>
<!-- SSDL content -->
<edmx:StorageModels>
<Schema Namespace="Model1.Store" Alias="Self" Provider="Devart.Data.Oracle" ProviderManifestToken="ORA" xmlns:store="http://schemas.microsoft.com/ado/2007/12/edm/EntityStoreSchemaGenerator" xmlns="http://schemas.microsoft.com/ado/2006/04/edm/ssdl">
<EntityContainer Name="Model1StoreContainer">
<EntitySet Name="TPH_TABLE" EntityType="Model1.Store.TPH_TABLE" >
<DefiningQuery>
SELECT ID, BASE_COLUMN, COLUMN_A, COLUMN_B,
CASE WHEN COLUMN_A IS NOT NULL THEN '1' ELSE NULL END AS "IS_TABLE_A"
FROM TPH_TABLE
</DefiningQuery>
</EntitySet>
</EntityContainer>
<EntityType Name="TPH_TABLE">
<Key>
<PropertyRef Name="ID" />
</Key>
<Property Name="ID" Type="int" Nullable="false" />
<Property Name="BASE_COLUMN" Type="VARCHAR2" MaxLength="20" />
<Property Name="COLUMN_A" Type="VARCHAR2" MaxLength="20" />
<Property Name="COLUMN_B" Type="VARCHAR2" MaxLength="20" />
<Property Name="IS_TABLE_A" Type="VARCHAR2" MaxLength="1" />
</EntityType>
</Schema>
</edmx:StorageModels>
<!-- CSDL content -->
<edmx:ConceptualModels>
<Schema Namespace="Model1" Alias="Self" xmlns="http://schemas.microsoft.com/ado/2006/04/edm">
<EntityContainer Name="Entities">
<EntitySet Name="TPH_TABLE" EntityType="Model1.TPH_TABLE" />
</EntityContainer>
<EntityType Name="TPH_TABLE" Abstract="true">
<Key>
<PropertyRef Name="ID" />
</Key>
<Property Name="ID" Type="Int32" Nullable="false" />
<Property Name="BASE_COLUMN" Type="String" MaxLength="20" Unicode="true" FixedLength="false" />
</EntityType>
<EntityType Name="TABLE_A" BaseType="Model1.TPH_TABLE" >
<Property Name="COLUMN_A" Type="String" Nullable="true" />
</EntityType>
<EntityType Name="TABLE_B" BaseType="Model1.TPH_TABLE" >
<Property Name="COLUMN_B" Type="String" Nullable="true" />
</EntityType>
</Schema>
</edmx:ConceptualModels>
<!-- C-S mapping content -->
<edmx:Mappings>
<Mapping Space="C-S" xmlns="urn:schemas-microsoft-com:windows:storage:mapping:CS">
<EntityContainerMapping StorageEntityContainer="Model1StoreContainer" CdmEntityContainer="Entities">
<EntitySetMapping Name="TPH_TABLE">
<EntityTypeMapping TypeName="Model1.TABLE_A">
<MappingFragment StoreEntitySet="TPH_TABLE">
<ScalarProperty Name="ID" ColumnName="ID" />
<ScalarProperty Name="BASE_COLUMN" ColumnName="BASE_COLUMN" />
<ScalarProperty Name="COLUMN_A" ColumnName="COLUMN_A" />
<Condition ColumnName="IS_TABLE_A" Value="1" />
</MappingFragment>
</EntityTypeMapping>
<EntityTypeMapping TypeName="Model1.TABLE_B">
<MappingFragment StoreEntitySet="TPH_TABLE">
<ScalarProperty Name="ID" ColumnName="ID" />
<ScalarProperty Name="BASE_COLUMN" ColumnName="BASE_COLUMN" />
<ScalarProperty Name="COLUMN_B" ColumnName="COLUMN_B" />
<Condition ColumnName="IS_TABLE_A" IsNull="true" />
</MappingFragment>
</EntityTypeMapping>
</EntitySetMapping>
</EntityContainerMapping>
</Mapping>
</edmx:Mappings>
</edmx:Runtime>
<!-- EF Designer content (DO NOT EDIT MANUALLY BELOW HERE) -->
<edmx:Designer xmlns="http://schemas.microsoft.com/ado/2007/06/edmx">
<edmx:Connection>
<DesignerInfoPropertySet>
<DesignerProperty Name="MetadataArtifactProcessing" Value="EmbedInOutputAssembly" />
</DesignerInfoPropertySet>
</edmx:Connection>
<edmx:Options>
<DesignerInfoPropertySet>
<DesignerProperty Name="ValidateOnBuild" Value="true" />
</DesignerInfoPropertySet>
</edmx:Options>
<!-- Diagram content (shape and connector positions) -->
<edmx:Diagrams>
<Diagram Name="Model4">
<EntityTypeShape EntityType="Model1.TPH_TABLE" Width="1.5" PointX="3" PointY="0.5" Height="1.2636116536458335" IsExpanded="true" />
<EntityTypeShape EntityType="Model1.TABLE_A" Width="1.5" PointX="1.75" PointY="2.75" Height="1.099264322916667" />
<EntityTypeShape EntityType="Model1.TABLE_B" Width="1.5" PointX="4.25" PointY="2.75" Height="1.099264322916667" />
<InheritanceConnector EntityType="Model1.TABLE_B" ManuallyRouted="false">
<ConnectorPoint PointX="4.375" PointY="1.7636116536458335" />
<ConnectorPoint PointX="4.375" PointY="2.75" />
</InheritanceConnector>
<InheritanceConnector EntityType="Model1.TABLE_A" ManuallyRouted="false">
<ConnectorPoint PointX="3.125" PointY="1.7636116536458335" />
<ConnectorPoint PointX="3.125" PointY="2.75" />
</InheritanceConnector></Diagram></edmx:Diagrams>
</edmx:Designer>
</edmx:Edmx>