views:

8

answers:

1

Within LINQ to Entities entity model (supported by .edmx file) sometimes column order changes within the tables. It may happen after you’ve edited the table structure (added or deleted columns, renamed them, etc.). As a result an automatically generated Create method changes and existing code becomes broken.

Example: You have entity called Item. It has columns ColA, ColB, ColC. Entity model designer generated method

Item.CreateItem(ColA, ColB, ColC)

for you. After some changes (which by the way have nothing to do with ColA, ColB, ColC !) the CreateItem method is now

Item.CreateItem(ColB, ColA, ColC)

As a result all your existing code, which calls CreateItem method, fails. Very annoying. Did anybody find the way how to persist the column order? Or at least how to control it? I tried to edit .edmx file directly and set up an order I need. But even this did not help. The Entity model designer is not following this order and it looks like it is picking up the order randomly.

A: 

I solve this by never using the Item.CreateItem() methods at all. You can use custom T4 to control codegen, but not using those methods is easier.

Craig Stuntz