4

I created a simple ASP.NET Dynamic Data application and it works perfectly on my development machine. When I deploy it, everything works fine as well except for the insert-page for an item that has a Many-to-Many relationship to other tables. The edit-page is fine, the Many-to-Many checkboxes show up. The server has .NET 4.0 installed.

I followed the instructions here: http://go.microsoft.com/fwlink/?LinkId=257395

Anyone have an idea what the problem could be?

Konstantin
  • 796
  • 1
  • 11
  • 32
Stefan
  • 1,719
  • 2
  • 15
  • 27
  • Hi, Stefan I'm facing the exact same issue, did you find a resolution? Thanks! Tim – TimS Jan 27 '13 at 22:37
  • "works fine as well except for the insert-page for an item that has a Many-to-Many" What does "does not work" mean? Is the DB schema exactly identical? Please try to recreate one of the databases as a copy of the other or use a sync tool. – usr Jan 27 '13 at 23:17
  • Indeed, more info about how it 'doesn't work' would be helpful. – David Ebbo Jan 28 '13 at 20:07
  • It's been a long time since I posted this question, so I'm not 100% sure, but I think what didn't work was that the Many-to-Many checkboxes showed up in the edit mode, but not in insert mode. The DB was the same. – Stefan Jan 28 '13 at 22:33

3 Answers3

0

I'm not 100% sure, but I think the versions of System.Web.DynamicData.dll and System.Web.DynamicData.Design.dll were different on my development machine and the server, so you may want to double check that. I also remember that I had to set up primary keys for all relationship tables, but that may have been a separate issue... This will teach me to answer my own question when I found a solution...

Stefan
  • 1,719
  • 2
  • 15
  • 27
0

@TimS: Might help if you could add any additional information on your situation - does this also work for you in one environment and not another? Do you know the versions of all installed components in both environments?

First two places I would look if I understand the question correctly are:

  1. Assuming you have some kind of automatic mapping from the form to the entity / model, do you need to initialize the entity or model with default values before loading the 'insert' page?

  2. Is your database identical as well in both setups - with same keys defined (I am assuming the code is identical...)

Matthew
  • 9,851
  • 4
  • 46
  • 77
0
  1. Make sure your many-to-many table has a primary key consisting of the primary keys of the two related tables.

  2. Make sure the table appears in the EDMX as a table and not a view (especially if you are using DB-first and you had to fix point 1).

  3. If you are using POCOs, then make sure the relationship properties (and the other properties) are either public or protected and are virtual.

  4. If you are using POCOs, make sure you fix-up the other side of the relationships on-change (default in POCO-T4s).

  5. If you are setting the relationship using two entities, e.g. a and b

    using:
    a.Bs.Add(b);

    Then if a was created as a proxy e.g.
    a = context.As.CreateObject();

    instead of:
    a = new A();

    It will be easier for EF to identify the changes.

    Also, if you are using an ObjectContext you could call
    context.SaveChanges(SaveOptions.DetectChangesBeforeSave | SaveOptions.AcceptAllChangesAfterSave);
    to help EF find the changes.

Danny Varod
  • 17,324
  • 5
  • 69
  • 111