views:

380

answers:

1

I have an interesting problem and wanted so see if anyone else has seen this. I've created a MVC 2 site using Visual studio 2010 beta 2. I'm using linq to sql data model objects with data annotations.

In my data model objects I'm using [ScaffoldColumn(false)] attribute to exclude the foreign key ID's from rendering to the UI when I use the EditorForModel method. For some reason the UI is rendering the foreign key table name.

e.g. if the foreign key is AccountID, i see the "account".

I wonder if this is a bug in the editorformodel or if I need to use a different/additional data annotation attribute to instruct editorformodel to not render anything.

+1  A: 

You Linq to SQL classes will have a property for the foreign key itself (AccountID) as well as an EntitySet property for the related records in the Accounts table. If you open up the auto-generated designer.cs file under your linq to sql dbml - you can view all the properties of each class. I think by default the templated helpers are only supposed to generate an editor for the first level of properties. There is a "deep-dive" option that will extend the generated editor to more levels of properties. Check out Brad Wilson's blog on the subject (near the end of the post).

In general, trying to throw your auto-generated Linq to SQL classes into your View or annotate them with attributes gets pretty hairy. It might be worth checking into strongly typed view models where you could specify only the properties you're interested in displaying in your view.

Bryan
Ah kewl! I see what you mean here. Thank you.