I was doing hands-on regarding accessing MS CRM data through OData service from Silverlight.
As a part of that I was practicing CRUD (Create, Read, Update and Delete) operations on the same.
I don’t face any problem reading create, read and delete operations.
Only problem I face is with read operations.
Let me describe my problem.
Data is fetched properly from CRM and URI generated after execution of query, works fine when executed independently in IE.
When I assign fetched data to listbox control it shows ‘SilverlightApplication43.CRMOdata.Contact’ and I want to show some specific Fields from contact such as First Name but somehow I am unable to do it.
I would appreciate if someone of you could help me.
My Code goes here
namespace SilverlightApplication43
{
public partial class MainPage : UserControl
{
public DataServiceCollection<Contact> _contacts;
System.Windows.Data.Binding list;
(myorgname)Context context;
public MainPage()
{
InitializeComponent();
MainPage_Loaded(this,new RoutedEventArgs() );
}
void MainPage_Loaded(object sender, RoutedEventArgs e)
{
var serviceUri = "http://crmdev:5555/(Myorgname)/XRMServices/2011/OrganizationData.svc/";
(Myorgname)Context ctx = new (Myorgname)Context(new Uri(serviceUri));
ctx.HttpStack = System.Data.Services.Client.HttpStack.ClientHttp;
ctx.UseDefaultCredentials = false;
ctx.Credentials = new NetworkCredential("administrator", "somepassword", "somedomain");
context = ODataServiceFactory.GetInstance<(Myorgname)Context>();
var query = from c in context.ContactSet
select c;
_contacts = null;
_contacts = new DataServiceCollection<Contact>();
_contacts.LoadCompleted += new EventHandler<LoadCompletedEventArgs>(_contacts_LoadCompleted);
_contacts.LoadAsync(query);
}
void _contacts_LoadCompleted(object sender, LoadCompletedEventArgs e)
{
var binding = (DataServiceCollection<Contact>)sender;
listBox1.ItemsSource = _contacts;
listBox1.ItemsSource = _contacts.ToList<Contact>();
}
}
}