2

Entity Framework is throwing error:

Test 'WorkerProcessService.Test.WorkerProcessMonitorTests.Test' failed: System.Data.UpdateException : Unable to update the EntitySet 'Processor' because it has a DefiningQuery and no <InsertFunction> element exists in the <ModificationFunctionMapping> element to support the current operation.
 at System.Data.SqlClient.SqlGen.DmlSqlGenerator.ExpressionTranslator.Visit(DbScanExpression expression)
 at System.Data.Common.CommandTrees.DbScanExpression.Accept(DbExpressionVisitor visitor)
 at System.Data.SqlClient.SqlGen.DmlSqlGenerator.GenerateInsertSql(DbInsertCommandTree tree, SqlVersion sqlVersion, List`1& parameters)
 at System.Data.SqlClient.SqlGen.SqlGenerator.GenerateSql(DbCommandTree tree, SqlVersion sqlVersion, List`1& parameters, CommandType& commandType, HashSet`1& paramsToForceNonUnicode)
 at System.Data.SqlClient.SqlProviderServices.CreateCommand(DbProviderManifest providerManifest, DbCommandTree commandTree)
 at System.Data.SqlClient.SqlProviderServices.CreateCommand(DbCommandTree commandTree)
 at System.Data.Mapping.Update.Internal.UpdateTranslator.CreateCommand(DbModificationCommandTree commandTree)
 at System.Data.Mapping.Update.Internal.DynamicUpdateCommand.CreateCommand(UpdateTranslator translator, Dictionary`2 identifierValues)
 at System.Data.Mapping.Update.Internal.DynamicUpdateCommand.Execute(UpdateTranslator translator, EntityConnection connection, Dictionary`2 identifierValues, List`1 generatedValues)
 at System.Data.Mapping.Update.Internal.UpdateTranslator.Update(IEntityStateManager stateManager, IEntityAdapter adapter)
 at System.Data.EntityClient.EntityAdapter.Update(IEntityStateManager entityCache)
 at System.Data.Objects.ObjectContext.SaveChanges(SaveOptions options)
 at System.Data.Objects.ObjectContext.SaveChanges()
 WorkerProcessMonitor.cs(79,0): at Star.Portal.Services.WorkerProcessMonitor.AddComponent(Byte[] component)
 WorkerProcessMonitorTests.cs(55,0): at WorkerProcessService.Test.WorkerProcessMonitorTests.Test()

I have a table like, and auto generated edmx model

CREATE TABLE [dbo].[Processor](
  [ProcessorID] [int] IDENTITY(1,1) NOT NULL,
  [ProcessorDLL] [varbinary](max) NULL,
)

The folowing fails to update

public void AddComponent(byte[] component)
        {
            Processor p = new Processor()
                              {
                                  ProcessorDLL = component,
                              };
             using (var cn = GetWorkerProcessEntities())
             {

                 cn.AddToProcessors(p);
                 cn.SaveChanges();
             }

        }

The question is: Do I have to do anything specific to implement binary storage in sql server?

3
  • Take a look at dotnetmonster.com/Uwe/Forum.aspx/dotnet-ado-net/21686/… Commented Jan 7, 2011 at 15:16
  • What is cn,AddToProcessors(p); Doing exactly? Commented Jan 7, 2011 at 16:06
  • have you set auto increament in Processor's ProcessorID??? Commented Jun 26, 2011 at 6:57

1 Answer 1

1

simple answer... No, I am storing images in a table with the same datatype (varbinary(max)).

Not knowing much about your code, i have simple test using local DB. this is my POCO and DBcontext. ( I dont use auto generated edmx )

using System.Data.Entity.ModelConfiguration;
public class Processor
{
    public int ProcessorId { get; set; }
    public byte[] ProcessorDLL { get; set; }
}
public class ProcessorConfiguration : EntityTypeConfiguration<Processor>
{
    public ProcessorConfiguration()
    {
        HasKey(i => i.ProcessorId);

        ToTable("Processor", "dbo");
    }
}
//DbContext
public class myContext : DbContext
{
    public DbSet<Processor> Processors { get; set; }

    protected override void OnModelCreating(DbModelBuilder modelBuilder)
    {
        modelBuilder.Configurations.Add(new ProcessorConfiguration());
        base.OnModelCreating(modelBuilder);
    }
}

Then when I add a new Processor, I use this

public void test()
    {
        myContext context = new myContext();

        Processor p = new Processor
        {
            ProcessorDLL = getSomeRandomByteArray()
        };

        context.Processors.Add(p);
        context.SaveChanges();
    }

and in my table:

ProcessorID: 1
ProcessorDLL: 0xFFD8FFE000104A46494600010200...

Hope this helped.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.