none
problem writing c# code for working with EF4.0 and sql server 2008 RRS feed

  • שאלה

  • Hey everyone, I strangling with a problem in the last days when I use EF4.0 working with sql server 2008.

    I want to write a code that creates&store data based on an existing database.

    My first table looks like that:

    ExistsTable

    DateColumn            PriceColumn1                     PriceColumn2

    01/01/2010 1601               101                                         108

    01/01/2010 1602               107                                         120                        

    ……..

    (this table and data exists  in the database and in the entity model)

    Now I want to write a code that loop through each row in the ExistsTable

    And generate/create data in to other table.

    The other table looks look that:

    InsertTable

    DateColumn            PriceColumn1                     PriceColumn2              ID(PK Filed)

    01/01/2010 1601               55                                           104                         1

    01/01/2010 1602               44                                           41                           2

    ……..

    (I know that it looks the same, but in this case this data is the result of the manipulation of a set of mathematical operations …. )

    The next step is to add additional data in a different table that relate to the InsertTable through the ID filed. And each rows in the InsertTable Will have sevral rows in the new table.

    The new table looks something like that:

    RelateTable

    DateColumn            PriceColumn1                     PriceColumn2              ID(FK Filed)

    01/01/2010 1601               55                                           56                           1

    01/01/2010 1602               77                                           41                           1

    ……..

     

    so my code look something like that:

    ContextName ctx = new ContextName();

    //select all rows in the ExistsTable

    Var Exists = from e in ctx.ExistsTable select e;

    //loop through

    Foreach (var exist in Exists)

    {

                    InsertTable newRow = new InsertTable();

                    newRow.DateColumn = Exists.DateCoulmn;

                    ….//insert data in each filed;

                   

                    Var close = from c in ctx.ExistsTable

    where c.DateColumn >exists.DateColumn select c;

                    foreach (var clos in close)

                    {

                                    RelateTable newrelateRow = new RelateRow();

                                    newrelateRow.DateCulomn = clos.DateCulomn;

                                    …//insert date in each filed

                                    newRow.InsertTable.AddOnewrelateRow);

                                    ctx.addToInsertTable(newRow);

                                   

                    }

    }

    Ctx.SaveChanges();

     

    (==im sorry im not posting the original code, im not allowed…J==)

    When I run it it throw an exception :

    " An unhandled exception of type 'System.Data.UpdateException' occurred in System.Data.Entity.dll

     

    Additional information: Unable to update the EntitySet 'Limits' because it has a DefiningQuery and no <InsertFunction> element exists in the <ModificationFunctionMapping> element to support the current operation."

    (in my code sample 'Limits' is the relateTable)

    Am I missing something? Can anyone see what is the problem?

     

    Tnx ahead J

     

     

    יום רביעי 22 דצמבר 2010 10:12