I가 다음 LINQ -왜이 LINQ가 특정 초기 값을 반환하지 않습니까?
문자a
어떤 제외한 모든 연락처를 반환
private static IEnumerable<AlphabetisedContact> _getGroupedContacts(int clientid)
{
return _getLiteContacts(clientid).GroupBy(c => c.Name[0]).Select(
g => new AlphabetisedContact { Initial = g.Key, Contacts = g.ToList() }).OrderBy(g => g.Initial); }
? 내가 놓친 게 있니?
편집 현재는 이런 식으로 뭔가를 반환 - 나는 이름 Bryn McWinkawonk
을위한을 가진 새 연락처를 추가하는 경우
[{
"$id": "1",
"Initial": "B",
"Contacts": [{
"$id": "2",
"ContactId": 12,
"Name": "Bryan Chiney",
"PrimaryContact": {
"$id": "3",
"Type": "Email",
"Value": "[email protected]"
},
"Avatar": "/images/avatars/default.jpg",
"UserId": null
}, {
"$id": "4",
"ContactId": 22,
"Name": "Bryan Billbags",
"PrimaryContact": {
"$id": "5",
"Type": "Email",
"Value": "[email protected]"
},
"Avatar": "/images/avatars/contacts/randomiser/1.jpg",
"UserId": 15
},
...
내가 ... 처음 Initial
블록이 A
연락처 내 번호를 기대 예, 그는 나타납니다,하지만 Alice Alikemen
...?
편집_getLiteContacts()
호출은 통과 PARAM으로 데이터베이스에 액세스 : -
private static IEnumerable<LiteContact> _getLiteContacts(int clientid)
{
return _getContacts(clientid).Select(c => new LiteContact()
{ ContactId = c.ContactId, ContactType = Enum.GetName(typeof (ContactTypeObject.Type), c.Type), Name = c.Name, PrimaryContact = _marshallFirstContactDetail(c.ContactId),
Avatar = c.Avatar, UserId = c.UserId }).ToList();
}
_getContacts()
: -
private static IEnumerable<Contact> _getContacts(int clientid)
{
using (var ctx = new atomicEntities())
{
var contacts = from c in ctx.Contacts
where c.ClientId == clientid
select c;
return contacts.ToList();
}
}
_marshallFirstContactDetail()
: -
private static Model.Contact.ContactDetail _marshallFirstContactDetail(int contact)
{
return _marshallContactDetails(contact).FirstOrDefault();
}
,691,765,-
private static IEnumerable<Model.Contact.ContactDetail> _marshallContactDetails(int contact)
{
using (var ctx = new atomicEntities())
{
var o = from d in ctx.ContactDetails
join cd in ctx.ContactDetailTypes on d.ContactDetailTypeId equals cd.ContactDetailTypeId
where d.ContactId == contact
select new Model.Contact.ContactDetail {Type = cd.Description, Value = d.Description};
return o.ToList();
}
}
예를 들어 데이터
contact_id client_id contact_name contact_type
8 22 Cain Allan 2
9 23 Bazrith Banners 2
10 22 Spencer Grep 1
12 22 Bryan Chiney 1
13 22 Dave Carter 4
15 22 Steve Tite 8
16 22 Henry Laythorpe 8
17 22 Chris Barker 8
18 22 Simon Cox 2
19 22 Russell Jacobs 1
20 22 John Wyndham 2
21 22 Isabel March 5
22 22 Bryan Billbags 2
23 22 Stu Plum 2
24 22 Pete Sorensen 7
25 22 Tom Francis 1
26 22 Rich McCormick 1
27 22 Tim Cain 4
28 22 Alex Ray-Harvey 1
29 22 Ryan Bennett 1
30 22 Alice Griswald 3
31 22 Archibald Smyth 3
32 22 Benjamin Franklin 5
도움말 감사합니다.
'a'로 시작하는 연락처가 있다면 제공해야합니다. 샘플 데이터와 예상 출력을 추가 할 때주의해야합니까? – BrokenGlass
@BrokenGlass가 요청에 따라 업데이트 됨) – dooburt
샘플 입력이 필요합니다. 코드가 작동해야합니다. 또한 JSON 출력 만 표시합니다. 문제가 C#에서 JSON으로 변환 될 수도 있습니다. 데이터가 사라지는 부분을 한 줄씩 살펴 보았습니까? – BrokenGlass