when I using below code :
using (ServiceContext svcContext = new ServiceContext(service))
{
var creditNote = svcContext.new_credit_noteSet.Where(c => c.new_credit_noteId == cnid).FirstOrDefault();
...
}
got this error:
System.InvalidCastException: Unable to cast object of type 'Microsoft.Xrm.Sdk.Entity' to type 'TCT.CRM.Model.new_credit_note'.
at System.Linq.Enumerable.<CastIterator>d__b1`1.MoveNext()
at Microsoft.Xrm.Sdk.Linq.PagedItemCollection`1.MoveNext()
at System.Linq.Enumerable.FirstOrDefault[TSource](IEnumerable`1 source)
at System.Linq.Queryable.FirstOrDefault[TSource](IQueryable`1 source)
at HP.Crm2013.Plugins.ServiceManage.sm_credit_note_update_post.CalculateTotalAmount(IOrganizationService service, Guid cnid)
at HP.Crm2013.Plugins.ServiceManage.sm_credit_note_update_post.Execute(IServiceProvider serviceProvider)
any help?
Awen