locked
Dynamic Data & Entity Framework Inheritence RRS feed

  • Question

  • User621401567 posted

    Keen to explore the abilities of Dynamic Data how well it integrates with the Entity Framework I created a simple test model.

    But when I tried to integrate it with Dynamic Data I got the following exception:

    The given key was not present in the dictionary

    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
    Exception Details: System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary.
    Source Error:

    Line 15:             // Only set ScaffoldAllTables = true if you are sure that you want all your tables
    Line 16:             // to support a scaffold (i.e. templated) view.
    Line 17:             model.RegisterContext(typeof(DemoDatabaseEntities), new ContextConfiguration() { ScaffoldAllTables = true });
    Line 18:
    Line 19:             routes.Add(new DynamicDataRoute("{table}/ListDetails.aspx")

    Has anybody managed to achieve this?

    Wednesday, June 18, 2008 5:00 AM

Answers

  • User-797310475 posted

    Hi Superfly,

    this is a known limitation of the current Entity Framework support (i.e. lacking inhertience support). We are looking at ways of improving this and will probably release an update EF model provider that will solve the problem as part of the Dynamic Data Extensions some time in the future.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, June 18, 2008 2:34 PM

All replies

  • User-2063762995 posted

    Hi Superfly, 

    Instead of accessing "DemoDatabaseEntities" directly, it should be referenced as the child of its model, otherwise it's going to be difficult to find.  I don't know your exact names, but try something like:

    model.RegisterContext(typeof(DemoDatabaseModel.DemoDatabaseEntities), new ContextConfiguration() { ScaffoldAllTables = true });
     - Erik
    Wednesday, June 18, 2008 1:13 PM
  • User-797310475 posted

    Hi Superfly,

    this is a known limitation of the current Entity Framework support (i.e. lacking inhertience support). We are looking at ways of improving this and will probably release an update EF model provider that will solve the problem as part of the Dynamic Data Extensions some time in the future.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, June 18, 2008 2:34 PM
  • User621401567 posted

    Erik, 

    Surely you're suggestion is smply refering to the Entities object by it's fully qualified name?

    That would have no bareing on this unless I had a bizzare naming conflict.

    Thursday, June 19, 2008 4:13 AM
  • User621401567 posted

    Marcin,

    Thanks for your response, I will keep an eye on the DDE project for future releases.

    Thursday, June 19, 2008 4:14 AM
  • User1582987959 posted

    Does the same limitation apply to LINQ to SQL DataContexts? I receive the same exception and a similar call stack:


    [KeyNotFoundException: The given key was not present in the dictionary.]
       System.ThrowHelper.ThrowKeyNotFoundException() +28
       System.Collections.Generic.Dictionary`2.get_Item(TKey key) +7452124
       System.Web.DynamicData.ModelProviders.DLinqAssociationProvider..ctor(DLinqColumnProvider column) +464
       System.Web.DynamicData.ModelProviders.DLinqColumnProvider.Initialize() +65
       System.Web.DynamicData.ModelProviders.DLinqTableProvider.Initialize() +157
       System.Web.DynamicData.ModelProviders.DLinqDataModelProvider..ctor(Object contextInstance, Func`1 contextFactory) +1224
       System.Web.DynamicData.ModelProviders.SchemaCreator.CreateDataModel(Object contextInstance, Func`1 contextFactory) +88
       System.Web.DynamicData.MetaModel.RegisterContext(Func`1 contextFactory, ContextConfiguration configuration) +518

    Can I assume that the single-table inheritance supported by LINQ to SQL causes this issues because of the lack of support in the Dynamic Data metadata provider for LINQ to SQL? This is on .NET FW 3.5 SP1 RTW that just came out.

    Tuesday, August 12, 2008 7:21 AM
  • User-797310475 posted

     It's possible. It also might be an issue with foreign key relationships that are pointed at non-PK unique columns. Do you have any of those in your model?

    Do you have a simple reprro (SQL table definition and how the inheritance is set up) that we could have a look at?

    Tuesday, August 12, 2008 11:46 AM
  • User1202816037 posted

    this is a known limitation of the current Entity Framework support (i.e. lacking inhertience support).

    Is there a place on the web where all limitations of EF support would be listed? It would make solving problems much easier, intstead of googling for every strange behaviour observed while using EF and Dynamic Data.

     

    Regards,

    Pawel

    Wednesday, September 3, 2008 9:29 AM
  • User-1005219520 posted

    I'm working on a list of know EF limitations/workarounds. We will fast track this as it's not scheduled to appear until sometime in October 08.

    Wednesday, September 3, 2008 3:42 PM
  • User-1005219520 posted

    I posted Differences When Working with the ADO.NET Entity Framework to LINQ to SQL on our ASP.Net UE Blog. Let me know if you have any questions.

    thanks - RickA

    Wednesday, September 10, 2008 8:08 PM
  • User1202816037 posted

     Thanks a lot, Rick!!!

    If i have any comments, I'll post it in that blog.

    Friday, September 12, 2008 9:54 AM