The problem is that the anonymous types you are using do not match. You need the properties to match the name, type, and order. Look at this:
ContactGroup.Add(new { ContactGroupKey = Convert.ToInt64(DB["ContactGroupKey", "0"]), ContactGroupTLK = Convert.ToInt64(DB["TranslationKey", "0"]), Desc = DB["Description", ""].ToString(), Contacts=GenerateList(Contact) });
This will be ContractGroupKey and ContactGruopTLK as long properties, and Contacts as List<T> , where T is your other anonymous type. You will need to change your initialization to be something like:
var sampleContact = new { ContactKey = 0L, }; var sampleContactList = new[] { sampleContact }.ToList(); var contactGroup = new[] { new { ContactGroupKey = 0L, ContactGroupTLK = 0L, Desc = "", Contacts = sampleContactList } }.ToList();
This may work - but it will be better for you to create named classes for this. Ultimately, it looks like they are likely to be significant entities in your system, so itβs worth the effort to model them as named types for starters.
(Side note: it should be consistent in your name, usually camelCased local variables, so you should use contactGroup , not contactGroup , etc.)
Jon skeet
source share