Wednesday 15 August 2012

C# creating a relationship between two iLists -



C# creating a relationship between two iLists -

i'm trying fetch name 1 ilist both contain same id.

public class notifications { [jsonproperty("note_id")] public int note_id { get; set;} [jsonproperty("sender_id")] public int sender_id { get; set;} public string sender_name { get; set; } [jsonproperty("receiver_id")] public int receiver_id { get; set; } [jsonproperty("document_id")] public int document_id { get; set; } [jsonproperty("search_name")] public string search_name { get; set; } [jsonproperty("unread")] public int unread { get; set; } } public class companydirectory { [jsonproperty("contact_id")] public int contact_id { get; set; } [jsonproperty("first_name")] public string first_name { get; set; } [jsonproperty("second_name")] public string second_name { get; set; } [jsonproperty("extension")] public string extension { get; set; } [jsonproperty("direct_dial")] public string direct_dial { get; set; } [jsonproperty("job_title")] public string job_title { get; set; } [jsonproperty("company_id")] public int company_id { get; set; } }

then i'm doing following, lists both populated fine. weird bit i'm getting errors saying companydir.first_name property doesn't exist, does?:

// occurs after class declaration public ilist<notifications> notes; public ilist<companydirectory> companydir; // ignore these both utilize same string they're created @ different parts of load process companydir = jsonconvert.deserializeobject<ilist<companydirectory>>(responsestring); notes = jsonconvert.deserializeobject<ilist<notifications>>(responsestring); // thought should able foreach(var s in notes){ var thename = companydir.first_name.where(contact_id.contains(s.sender_id)) }

you should linq , lambda expressions:

var firstnames = companydir.where(c => c.contact_id == s.sender_id) .select(c => c.first_name) .tolist();

now have list of firstnames. list, because there may 0 or more hits constraint.

c#

No comments:

Post a Comment