我正在尝试使用 LINQ 和实体框架创建一个包含大量联系人的 rolodex 样式分组。
我有一个Contacts模型,它需要包装在一个GroupedContacts模型中,其中包含一个Initial属性。我想,如果存在信件的记录,要填写的初始属性和要填充的Contacts列表:-
public char Initial { get; set; }
public List<Contacts> Contacts { get; set; }
任何人都可以借给我他们的 LINQ 禅级别来实现这一点吗?
为了完整起见,我的联系人get目前如下所示:-
using (var ctx = new atomicEntities())
            {
                var contacts = from c in ctx.Contacts
                               where c.ClientId == clientid
                               select c;
                return contacts.ToList();
            }
一如既往,感谢您的帮助:)
编辑
我重新阅读了我的问题几次,觉得它有点含糊。为了澄清,我试图创建这样的数据: -
{
        initial: 'c',
        contacts: [
            {
                name: 'Charlie Chaplin',
                primaryContact: {
                    type: 'phone',
                    value: '0123456789'
                }
            },
            {
                name: 'Charlie Sheen',
                primaryContact: {
                    type: 'email',
                    value: 'sheen@charliepower.com'
                }
            },
            {
                name: 'Colin Caterpiller',
                primaryContact: {
                    type: 'email',
                    value: 'colin@caterpiller.com'
                }
            }
        ]
    }