I want to call web services and store in List but not able to add i know the return type is not matching for both.
May i know how to consume web service and store in List.
I have class which inherit with object, System.Runtime.Serialization.IExtensibleDataObject, System.ComponentModel.INotifyPropertyChanged
Should I use LINQ.
Signature of GetInitiatorsListByWorkflow:
public Almarai.GiveAway.GetInitiatorList.INITIATORS_LIST GetInitiatorsListByWorkflow(string userId, string WorkflowTypeCode) {
return base.Channel.GetInitiatorsListByWorkflow(userId, WorkflowTypeCode);
}
Refrence:
[System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/IMasterDataService/GetInitiatorsListByWorkflow", ReplyAction="http://tempuri.org/IMasterDataService/GetInitiatorsListByWorkflowResponse")]
[System.ServiceModel.FaultContractAttribute(typeof(Almarai.GiveAway.GetInitiatorList.CustomFaultException), Action="http://tempuri.org/IMasterDataService/GetInitiatorsListByWorkflowCustomFaultExcep" +
"tionFault", Name="CustomFaultException", Namespace="http://schemas.datacontract.org/2004/07/Almarai.Web.Services.MasterData")]
Almarai.GiveAway.GetInitiatorList.INITIATORS_LIST GetInitiatorsListByWorkflow(string userId, string WorkflowTypeCode);
My class :
public partial class INITIATORS_LIST : object, System.Runtime.Serialization.IExtensibleDataObject, System.ComponentModel.INotifyPropertyChanged
{
[System.NonSerializedAttribute()]
private System.Runtime.Serialization.ExtensionDataObject extensionDataField;
[System.Runtime.Serialization.OptionalFieldAttribute()]
private Almarai.GiveAway.GetInitiatorList.ALM_COMPANY_M[] CompaniesField;
[System.Runtime.Serialization.OptionalFieldAttribute()]
private Almarai.GiveAway.GetInitiatorList.ALM_COUNTRY_M[] CountriesField;
[System.Runtime.Serialization.OptionalFieldAttribute()]
private Almarai.GiveAway.GetInitiatorList.ALM_DIVISION_M[] DivisionsField;
[System.Runtime.Serialization.OptionalFieldAttribute()]
private Almarai.GiveAway.GetInitiatorList.LOCATION[] LocationsField;
[global::System.ComponentModel.BrowsableAttribute(false)]
public System.Runtime.Serialization.ExtensionDataObject ExtensionData
{
get
{
return this.extensionDataField;
}
set
{
this.extensionDataField = value;
}
}
[System.Runtime.Serialization.DataMemberAttribute()]
public Almarai.GiveAway.GetInitiatorList.ALM_COMPANY_M[] Companies
{
get
{
return this.CompaniesField;
}
set
{
if ((object.ReferenceEquals(this.CompaniesField, value) != true))
{
this.CompaniesField = value;
this.RaisePropertyChanged("Companies");
}
}
}
[System.Runtime.Serialization.DataMemberAttribute()]
public Almarai.GiveAway.GetInitiatorList.ALM_COUNTRY_M[] Countries
{
get
{
return this.CountriesField;
}
set
{
if ((object.ReferenceEquals(this.CountriesField, value) != true))
{
this.CountriesField = value;
this.RaisePropertyChanged("Countries");
}
}
}
[System.Runtime.Serialization.DataMemberAttribute()]
public Almarai.GiveAway.GetInitiatorList.ALM_DIVISION_M[] Divisions
{
get
{
return this.DivisionsField;
}
set
{
if ((object.ReferenceEquals(this.DivisionsField, value) != true))
{
this.DivisionsField = value;
this.RaisePropertyChanged("Divisions");
}
}
}
[System.Runtime.Serialization.DataMemberAttribute()]
public Almarai.GiveAway.GetInitiatorList.LOCATION[] Locations
{
get
{
return this.LocationsField;
}
set
{
if ((object.ReferenceEquals(this.LocationsField, value) != true))
{
this.LocationsField = value;
this.RaisePropertyChanged("Locations");
}
}
}
[System.Runtime.Serialization.DataMemberAttribute()]
public Almarai.GiveAway.GetInitiatorList.REGION[] Regions
{
get
{
return this.RegionsField;
}
set
{
if ((object.ReferenceEquals(this.RegionsField, value) != true))
{
this.RegionsField = value;
this.RaisePropertyChanged("Regions");
}
}
}
[System.Runtime.Serialization.DataMemberAttribute()]
public Almarai.GiveAway.GetInitiatorList.ALM_WKFLW_TYPE_M[] WorkflowTypes
{
get
{
return this.WorkflowTypesField;
}
set
{
if ((object.ReferenceEquals(this.WorkflowTypesField, value) != true))
{
this.WorkflowTypesField = value;
this.RaisePropertyChanged("WorkflowTypes");
}
}
}
public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;
protected void RaisePropertyChanged(string propertyName)
{
System.ComponentModel.PropertyChangedEventHandler propertyChanged = this.PropertyChanged;
if ((propertyChanged != null))
{
propertyChanged(this, new System.ComponentModel.PropertyChangedEventArgs(propertyName));
}
}
}
My method:
[WebMethod]
public static List<INITIATORS_LIST> GetCountriesName(string UserID)
{
GetInitiatorList.MasterDataServiceClient oClient = new GetInitiatorList.MasterDataServiceClient();
List<INITIATORS_LIST> lst = new List<INITIATORS_LIST>();
var INITIATORS_LIST = new INITIATORS_LIST()
{
ExtensionData =
oClient.GetInitiatorsListByWorkflow("SAU", "SaudiArebia")//Error on this Line
};
return lst;
}
I am calling web services and returning into list but I am not able to do same.
I want to bind drop down list with web services.
I have added INITIATORS_LIST class which contain all field which I want to bind in Drop down list like Companies, Countries, Divisions, Location... So on. How can I achieve any alternate method may I accept please ?
Sample JSON Data
{"Companies":[{"ACTIVE":true,"COMPANY_ID":1,"CompanyCode":"1000","CompanyName":"Almarai Company","CountryCode":"SAU","CountryName":"Saudi Arabia","DivisionCode":"1000","DivisionId":1,"DivisionName":"Sales"},{"ACTIVE":true,"COMPANY_ID":6,"CompanyCode":"4000","CompanyName":"Almarai Co. Bahrain WLL","CountryCode":"BAH","CountryName":"Bahrain","DivisionCode":"1000","DivisionId":1,"DivisionName":"Sales"},{"ACTIVE":true,"COMPANY_ID":8,"CompanyCode":"5000","CompanyName":"Bustan Al Khaleej Est.","CountryCode":"UAE","CountryName":"United Arab Emirates","DivisionCode":"1000","DivisionId":1,"DivisionName":"Sales"},{"ACTIVE":true,"COMPANY_ID":11,"CompanyCode":"5200","CompanyName":"ALMARAI EMIRATES COMPANY L.L.C","CountryCode":"UAE","CountryName":"United Arab Emirates","DivisionCode":"1000","DivisionId":1,"DivisionName":"Sales"},{"ACTIVE":true,"COMPANY_ID":15,"CompanyCode":"6000","CompanyName":"Al Kharafi Brothers","CountryCode":"KWT","CountryName":"Kuwait","DivisionCode":"1000","DivisionId":1,"DivisionName":"Sales"},{"ACTIVE":true,"COMPANY_ID":18,"CompanyCode":"7000","CompanyName":"Arabian Planets Company","CountryCode":"OMN","CountryName":"Oman","DivisionCode":"1000","DivisionId":1,"DivisionName":"Sales"}],"Countries":[{"COUNTRY_ACTIVE":true,"COUNTRY_M_ID":1,"CountryCode":"SAU","CountryName":"Saudi Arabia","DivisionCode":"1000","DivisionId":1,"DivisionName":"Sales"},{"COUNTRY_ACTIVE":true,"COUNTRY_M_ID":3,"CountryCode":"UAE","CountryName":"United Arab Emirates","DivisionCode":"1000","DivisionId":1,"DivisionName":"Sales"},{"COUNTRY_ACTIVE":true,"COUNTRY_M_ID":4,"CountryCode":"BAH","CountryName":"Bahrain","DivisionCode":"1000","DivisionId":1,"DivisionName":"Sales"},{"COUNTRY_ACTIVE":true,"COUNTRY_M_ID":5,"CountryCode":"OMN","CountryName":"Oman","DivisionCode":"1000","DivisionId":1,"DivisionName":"Sales"},{"COUNTRY_ACTIVE":true,"COUNTRY_M_ID":7,"CountryCode":"KWT","CountryName":"Kuwait","DivisionCode":"1000","DivisionId":1,"DivisionName":"Sales"}],"Divisions":[{"ACTIVE":true,"CompanyCode":null,"CompanyName":null,"CountryCode":null,"CountryName":null,"DB_CONNECTION_STRING":null,"DivisionCode":"1000","DivisionId":1,"DivisionName":"Sales","WEB_URL":null}],"Locations":
ALM_COUNTRY_M class:
public partial class ALM_COUNTRY_M : object, System.Runtime.Serialization.IExtensibleDataObject,
System.ComponentModel.INotifyPropertyChanged {
[System.NonSerializedAttribute()]
private System.Runtime.Serialization.ExtensionDataObject extensionDataField;
[System.Runtime.Serialization.OptionalFieldAttribute()]
private bool COUNTRY_ACTIVEField;
[System.Runtime.Serialization.OptionalFieldAttribute()]
private int COUNTRY_M_IDField;
[System.Runtime.Serialization.OptionalFieldAttribute()]
private string CountryCodeField;
[System.Runtime.Serialization.OptionalFieldAttribute()]
private string CountryNameField;
[System.Runtime.Serialization.OptionalFieldAttribute()]
private string DivisionCodeField;
[System.Runtime.Serialization.OptionalFieldAttribute()]
private int DivisionIdField;
[System.Runtime.Serialization.OptionalFieldAttribute()]
private string DivisionNameField;
[global::System.ComponentModel.BrowsableAttribute(false)]
public System.Runtime.Serialization.ExtensionDataObject ExtensionData {
get {
return this.extensionDataField;
}
set {
this.extensionDataField = value;
}
}
[System.Runtime.Serialization.DataMemberAttribute()]
public bool COUNTRY_ACTIVE {
get {
return this.COUNTRY_ACTIVEField;
}
set {
if ((this.COUNTRY_ACTIVEField.Equals(value) != true)) {
this.COUNTRY_ACTIVEField = value;
this.RaisePropertyChanged("COUNTRY_ACTIVE");
}
}
}
[System.Runtime.Serialization.DataMemberAttribute()]
public int COUNTRY_M_ID {
get {
return this.COUNTRY_M_IDField;
}
set {
if ((this.COUNTRY_M_IDField.Equals(value) != true)) {
this.COUNTRY_M_IDField = value;
this.RaisePropertyChanged("COUNTRY_M_ID");
}
}
}
[System.Runtime.Serialization.DataMemberAttribute()]
public string CountryCode {
get {
return this.CountryCodeField;
}
set {
if ((object.ReferenceEquals(this.CountryCodeField, value) != true)) {
this.CountryCodeField = value;
this.RaisePropertyChanged("CountryCode");
}
}
}
[System.Runtime.Serialization.DataMemberAttribute()]
public string CountryName {
get {
return this.CountryNameField;
}
set {
if ((object.ReferenceEquals(this.CountryNameField, value) != true)) {
this.CountryNameField = value;
this.RaisePropertyChanged("CountryName");
}
}
}
[System.Runtime.Serialization.DataMemberAttribute()]
public string DivisionCode {
get {
return this.DivisionCodeField;
}
set {
if ((object.ReferenceEquals(this.DivisionCodeField, value) != true)) {
this.DivisionCodeField = value;
this.RaisePropertyChanged("DivisionCode");
}
}
}
[System.Runtime.Serialization.DataMemberAttribute()]
public int DivisionId {
get {
return this.DivisionIdField;
}
set {
if ((this.DivisionIdField.Equals(value) != true)) {
this.DivisionIdField = value;
this.RaisePropertyChanged("DivisionId");
}
}
}
[System.Runtime.Serialization.DataMemberAttribute()]
public string DivisionName {
get {
return this.DivisionNameField;
}
set {
if ((object.ReferenceEquals(this.DivisionNameField, value) != true)) {
this.DivisionNameField = value;
this.RaisePropertyChanged("DivisionName");
}
}
}
public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;
protected void RaisePropertyChanged(string propertyName) {
System.ComponentModel.PropertyChangedEventHandler propertyChanged = this.PropertyChanged;
if ((propertyChanged != null)) {
propertyChanged(this, new System.ComponentModel.PropertyChangedEventArgs(propertyName));
}
}
}
INITIATORS_LIST Class:
public partial class INITIATORS_LIST : object, System.Runtime.Serialization.IExtensibleDataObject, System.ComponentModel.INotifyPropertyChanged {
[System.NonSerializedAttribute()]
private System.Runtime.Serialization.ExtensionDataObject extensionDataField;
[System.Runtime.Serialization.OptionalFieldAttribute()]
private Almarai.GiveAway.GetInitiatorList.ALM_COMPANY_M[] CompaniesField;
[System.Runtime.Serialization.OptionalFieldAttribute()]
private Almarai.GiveAway.GetInitiatorList.ALM_COUNTRY_M[] CountriesField;
[System.Runtime.Serialization.OptionalFieldAttribute()]
private Almarai.GiveAway.GetInitiatorList.ALM_DIVISION_M[] DivisionsField;
[System.Runtime.Serialization.OptionalFieldAttribute()]
private Almarai.GiveAway.GetInitiatorList.LOCATION[] LocationsField;
[System.Runtime.Serialization.OptionalFieldAttribute()]
private Almarai.GiveAway.GetInitiatorList.REGION[] RegionsField;
[System.Runtime.Serialization.OptionalFieldAttribute()]
private Almarai.GiveAway.GetInitiatorList.ALM_WKFLW_TYPE_M[] WorkflowTypesField;
[global::System.ComponentModel.BrowsableAttribute(false)]
public System.Runtime.Serialization.ExtensionDataObject ExtensionData {
get {
return this.extensionDataField;
}
set {
this.extensionDataField = value;
}
}
[System.Runtime.Serialization.DataMemberAttribute()]
public Almarai.GiveAway.GetInitiatorList.ALM_COMPANY_M[] Companies {
get {
return this.CompaniesField;
}
set {
if ((object.ReferenceEquals(this.CompaniesField, value) != true)) {
this.CompaniesField = value;
this.RaisePropertyChanged("Companies");
}
}
}
[System.Runtime.Serialization.DataMemberAttribute()]
public Almarai.GiveAway.GetInitiatorList.ALM_COUNTRY_M[] Countries {
get {
return this.CountriesField;
}
set {
if ((object.ReferenceEquals(this.CountriesField, value) != true)) {
this.CountriesField = value;
this.RaisePropertyChanged("Countries");
}
}
}
[System.Runtime.Serialization.DataMemberAttribute()]
public Almarai.GiveAway.GetInitiatorList.ALM_DIVISION_M[] Divisions {
get {
return this.DivisionsField;
}
set {
if ((object.ReferenceEquals(this.DivisionsField, value) != true)) {
this.DivisionsField = value;
this.RaisePropertyChanged("Divisions");
}
}
}
[System.Runtime.Serialization.DataMemberAttribute()]
public Almarai.GiveAway.GetInitiatorList.LOCATION[] Locations {
get {
return this.LocationsField;
}
set {
if ((object.ReferenceEquals(this.LocationsField, value) != true)) {
this.LocationsField = value;
this.RaisePropertyChanged("Locations");
}
}
}
[System.Runtime.Serialization.DataMemberAttribute()]
public Almarai.GiveAway.GetInitiatorList.REGION[] Regions {
get {
return this.RegionsField;
}
set {
if ((object.ReferenceEquals(this.RegionsField, value) != true)) {
this.RegionsField = value;
this.RaisePropertyChanged("Regions");
}
}
}
[System.Runtime.Serialization.DataMemberAttribute()]
public Almarai.GiveAway.GetInitiatorList.ALM_WKFLW_TYPE_M[] WorkflowTypes {
get {
return this.WorkflowTypesField;
}
set {
if ((object.ReferenceEquals(this.WorkflowTypesField, value) != true)) {
this.WorkflowTypesField = value;
this.RaisePropertyChanged("WorkflowTypes");
}
}
}
public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;
protected void RaisePropertyChanged(string propertyName) {
System.ComponentModel.PropertyChangedEventHandler propertyChanged = this.PropertyChanged;
if ((propertyChanged != null)) {
propertyChanged(this, new System.ComponentModel.PropertyChangedEventArgs(propertyName));
}
}
}
Reference:
public Almarai.GiveAway.GetInitiatorList.INITIATORS_LIST GetInitiatorsListByWorkflow(string userId, string WorkflowTypeCode) {
return base.Channel.GetInitiatorsListByWorkflow(userId, WorkflowTypeCode);
}
[System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/IMasterDataService/GetInitiatorsListByWorkflow", ReplyAction="http://tempuri.org/IMasterDataService/GetInitiatorsListByWorkflowResponse")]
[System.ServiceModel.FaultContractAttribute(typeof(Almarai.GiveAway.GetInitiatorList.CustomFaultException), Action="http://tempuri.org/IMasterDataService/GetInitiatorsListByWorkflowCustomFaultExcep" +
"tionFault", Name="CustomFaultException", Namespace="http://schemas.datacontract.org/2004/07/Almarai.Web.Services.MasterData")]
Almarai.GiveAway.GetInitiatorList.INITIATORS_LIST GetInitiatorsListByWorkflow(string userId, string WorkflowTypeCode);
Country class: (Should I change this class for Each different field like Company, Country, Region....so on)
public class CountryList
{
public CountryList(INITIATORS_LIST data)
{
ExtensionData = data;
}
public INITIATORS_LIST ExtensionData { get; internal set; }
}
My Method: (How should I modify my method)
[WebMethod]
public static List<CountryList> GetCountriesName(string UserID)
{
GetInitiatorList.MasterDataServiceClient oClient = new GetInitiatorList.MasterDataServiceClient();
string userid = "approver01";
string work = "4";
List<CountryList> countries = oClient.GetInitiatorsListByWorkflow(userid, work); // Error on this line
foreach (Country c in countries)
{
lst.Add(c.Name);
}
return lst; //Error on this line
}
I am not able to Add into list is there other approch ?
I know due to return type am not able to do but
The GetInitiatorsListByWorkflow method returns a Almarai.GiveAway.GetInitiatorList.INITIATORS_LIST object, not a List<CountryList>. Likewise your GetCountriesName method returns List<CountryList>, not whatever the type of your (undefined in the code shown) lst variable is. That's why you have errors - you can't just randomly assign objects to variables which are the wrong type.
Anyway it seems that for your countries list you actually want to use two properties from the ALM_COUNTRY_M class. The INITIATORS_LIST contains an array of objects of that type.
So what you really need to do is get the array of ALM_COUNTRY_M objects from the INITIATORS_LIST returned by the GetInitiatorsListByWorkflow method, and loop through them, and for each one, create an equivalent instance of CountryList, set its properties using the values in the ALM_COUNTRY_M object, and add that to the list to be returned.
Something like this (untested):
[WebMethod]
public static List<CountryList> GetCountriesName(string UserID)
{
GetInitiatorList.MasterDataServiceClient oClient = new GetInitiatorList.MasterDataServiceClient();
string userid = "approver01";
string work = "4";
Almarai.GiveAway.GetInitiatorList.INITIATORS_LIST initiatorsList = oClient.GetInitiatorsListByWorkflow(userid, work); //get data from webservice
Almarai.GiveAway.GetInitiatorList.ALM_COUNTRY_M[] countryMList = initiatorsList.Countries; //get list of countries from the data returned by the webservice
List<CountryList> countries = new List<CountryList>(); //create an empty list which will be populated with data from the webservice
//loop through list of countries returned from webservice
foreach (Almarai.GiveAway.GetInitiatorList.ALM_COUNTRY_M country in countryMList)
{
//add new instance of CountryList using fields from the webservice class
countries.Add(new CountryList() {
CountryCode = country.CountryCode,
CountryName = country.CountryName
});
}
return countries; //return the completed list of countries
}
The CountryList class should be defined more like this:
public class CountryList
{
public string CountryCode { get; set; }
public string CountryName { get; set; }
}
P.S. It would be more meaningful to rename the CountryList class to Country, since each object only represents a single country. It's the List<> part which defines a list. But that's a separate issue for you to decide.
I am trying to Serialize/Deserialize a object, but I am getting an "ArgumentException" on deserialization.
My Object is this:
public class Findoc
{
public Findoc()
{
}
private string _ID = string.Empty;
public string ID
{
get { return this._ID; }
set { _ID = value; }
}
private int _lastindex;
public int lastindex
{
get { return this._lastindex; }
set { _lastindex = value; }
}
private string _SilogiDate;
public string SilogiDate
{
get { return this._SilogiDate; }
set { _SilogiDate = value; }
}
private Truck _TR;
public Truck TR
{
get { return this._TR; }
set { _TR = value; }
}
private Routing _RT;
public Routing RT
{
get { return this._RT; }
set { _RT = value; }
}
private KentroKostous _KK;
public KentroKostous KK
{
get { return this._KK; }
set { _KK = value; }
}
private Busunit _BU;
public Busunit BU
{
get { return this._BU; }
set { _BU = value; }
}
private string _FINCODE = string.Empty;
public string FINCODE
{
get { return this._FINCODE; }
set { _FINCODE = value; }
}
private string _FINSTATE = "";
public string FINSTATE
{
get { return this._FINSTATE; }
set { _FINSTATE = value; }
}
private string _STAGE = "";
public string STAGE
{
get { return this._STAGE; }
set { _STAGE = value; }
}
private string _SPCS = "";
public string SPCS
{
get { return this._SPCS; }
set { _SPCS = value; }
}
private string _SPCSCODE = "";
public string SPCSCODE
{
get { return this._SPCSCODE; }
set { _SPCSCODE = value; }
}
private string _MTRSTS = "";
public string MTRSTS
{
get { return this._MTRSTS; }
set { _MTRSTS = value; }
}
private string _PARAGOMENO = "";
public string PARAGOMENO
{
get { return this._PARAGOMENO; }
set { _PARAGOMENO = value; }
}
private double _PARAGOMENOQTY1;
public double PARAGOMENOQTY1
{
get { return this._PARAGOMENOQTY1; }
set { _PARAGOMENOQTY1 = value; }
}
private double _PARAGOMENOQTY2;
public double PARAGOMENOQTY2
{
get { return this._PARAGOMENOQTY2; }
set { _PARAGOMENOQTY2 = value; }
}
private Boolean _PARAGOMENOUSESN;
public Boolean PARAGOMENOUSESN
{
get { return this._PARAGOMENOUSESN; }
set { _PARAGOMENOUSESN = value; }
}
private Boolean _EDITABLE = true;
public Boolean EDITABLE
{
get { return this._EDITABLE; }
set { _EDITABLE = value; }
}
private Boolean _ISPRINT;
public Boolean ISPRINT
{
get { return this._ISPRINT; }
set { _ISPRINT = value; }
}
private Boolean _ISCANCELED;
public Boolean ISCANCELED
{
get { return this._ISCANCELED; }
set { _ISCANCELED = value; }
}
private int _SOSOURCE;
public int SOSOURCE
{
get { return this._SOSOURCE; }
set { _SOSOURCE = value; }
}
private Series _series;
public Series Series
{
get { return this._series; }
set { _series = value; }
}
private string _TICK = string.Empty;
public string TICK
{
get { return this._TICK; }
set { _TICK = value; }
}
private string _COMMENTS = "";
public string COMMEMTS
{
get { return this._COMMENTS; }
set { _COMMENTS = value; }
}
private string _COMMENTS1 = "";
public string COMMEMTS1
{
get { return this._COMMENTS1; }
set { _COMMENTS1 = value; }
}
private string _COMMENTS2 = "";
public string COMMEMTS2
{
get { return this._COMMENTS2; }
set { _COMMENTS2 = value; }
}
private string _karfoto_fincode = "";//gia tis eisprakseis
public string Karfoto_fincode
{
get { return this._karfoto_fincode; }
set { _karfoto_fincode = value; }
}
private List<Mtrline> _Mtrlines;
public List<Mtrline> Mtrlines
{
get { return this._Mtrlines; }
set { _Mtrlines = value; }
}
}
public class SnLine
{
private string _TICK;
public string TICK
{
get { return this._TICK; }
set { _TICK = value; }
}
private string _sn;
public string sn
{
get { return this._sn; }
set { _sn = value; }
}
}
public class Mtrline
{
public Mtrline(Findoc findoc)
{
}
private List<SnLine> _SnLines;
public List<SnLine> SnLines
{
get { return this._SnLines; }
set { _SnLines = value; }
}
private int _position;
public int position
{
get { return this._position; }
set { _position = value; }
}
private string _guid;
public string guid
{
get { return this._guid; }
set { _guid = value; }
}
private WhouseObj _Whouse1;
public WhouseObj Whouse1
{
get { return this._Whouse1; }
set { _Whouse1 = value; }
}
private WhouseObj _Whouse2;
public WhouseObj Whouse2
{
get { return this._Whouse2; }
set { _Whouse2 = value; }
}
private string _WHOUSE = "";
public string WHOUSE
{
get { return this._WHOUSE; }
set { _WHOUSE = value; }
}
private string _WHOUSESEC = "";
public string WHOUSESEC
{
get { return this._WHOUSESEC; }
set { _WHOUSESEC = value; }
}
private string _SPCS;
public string SPCS
{
get { return this._SPCS; }
set { _SPCS = value; }
}
private string _MPKCODE;
public string MPKCODE
{
get { return this._MPKCODE; }
set { _MPKCODE = value; }
}
private string _whousebin1remain;
public string Whousebin1remain
{
get { return this._whousebin1remain; }
set { _whousebin1remain = value; }
}
private string _whousebin2remain;
public string Whousebin2remain
{
get { return this._whousebin2remain; }
set { _whousebin2remain = value; }
}
private int _NEWLINE;
public int NEWLINE
{
get { return this._NEWLINE; }
set { _NEWLINE = value; }
}
private string _CCCPACK1;
public string CCCPACK1
{
get {
if (_CCCPACK1 == null)
return "";
else
return this._CCCPACK1;
}
set { _CCCPACK1 = value; }
}
public string _CCCPACK2;
public string CCCPACK2
{
get
{
if (_CCCPACK2 == null)
return "";
else
return this._CCCPACK2;
}
set { _CCCPACK2 = value; }
}
private string _PAKETO = "";
public string PAKETO
{
get { return this._PAKETO; }
set { _PAKETO = value; }
}
private string _TICK;
public string TICK
{
get { return this._TICK; }
set { _TICK = value; }
}
private string _AAA;
public string AAA
{
get { return this._AAA; }
set { _AAA = value; }
}
private MtrlModel _MTRL_Object;
public MtrlModel MTRL_Object
{
get { return this._MTRL_Object; }
set { _MTRL_Object = value; }
}
private double _SUMQTY; // SUMQTY ana eidos
public double SUMQTY
{
get { return this._SUMQTY; }
set { _SUMQTY = value; }
}
private double _SUMQTY2; // SUMQTY ana eidos
public double SUMQTY2
{
get { return this._SUMQTY2; }
set { _SUMQTY2 = value; }
}
private double _QTY; // posotita T
public double QTY
{
get { return this._QTY; }
set { _QTY = value; }
}
private double _QTY1;
public double QTY1
{
get { return this._QTY1; }
set { _QTY1 = value; }
}
private double _QTY2;
public double QTY2
{
get { return this._QTY2; }
set { _QTY2 = value; }
}
private double _QTYP;
public double QTYP
{
get { return this._QTYP; }
set { _QTYP = value; }
}
private string _FIELDS = "";
public string FIELDS
{
get { return this._FIELDS; }
set { _FIELDS = value; }
}
private string _COMMENTS = "";
public string COMMENTS
{
get { return this._COMMENTS; }
set { _COMMENTS = value; }
}
private string _COMMENTS1 = "";
public string COMMENTS1
{
get { return this._COMMENTS1; }
set { _COMMENTS1 = value; }
}
private string _COMMENTS2 = "";
public string COMMENTS2
{
get { return this._COMMENTS2; }
set { _COMMENTS2 = value; }
}
private CDIMLINE _CDIMNO1_Object;
public CDIMLINE CDIMNO1_Object
{
get { return this._CDIMNO1_Object; }
set { _CDIMNO1_Object = value; }
}
private string _CDIMNO1;
public string CDIMNO1
{
get
{
if (this._CDIMNO1_Object != null)
return this._CDIMNO1_Object.NAME;
else
return "";
}
set { _CDIMNO1 = value; }
}
private CDIMLINE _CDIMNO2_Object;
public CDIMLINE CDIMNO2_Object
{
get { return this._CDIMNO2_Object; }
set { _CDIMNO2_Object = value; }
}
private string _CDIMNO2;
public string CDIMNO2
{
get
{
if (this._CDIMNO2_Object != null)
return this._CDIMNO2_Object.NAME;
else
return "";
}
set { _CDIMNO2 = value; }
}
private CDIMLINE _CDIMNO3_Object;
public CDIMLINE CDIMNO3_Object
{
get { return this._CDIMNO3_Object; }
set { _CDIMNO3_Object = value; }
}
private string _CDIMNO3;
public string CDIMNO3
{
get
{
if (this._CDIMNO3_Object != null)
return this._CDIMNO3_Object.NAME;
else
return "";
}
set { _CDIMNO3 = value; }
}
private Lot _LOT;
public Lot LOT
{
get { return this._LOT; }
set { _LOT = value; }
}
private string _CODE = "";
public string CODE
{
get { return this._MTRL_Object.CODE; }
set { _CODE = value; }
}
private string _MTRPLACE = "";
public string MTRPLACE
{
get { return this._MTRL_Object.MTRPLACE; }
set { _MTRPLACE = value; }
}
private double _SUMWHOUSE;
public double SUMWHOUSE
{
get { return this._MTRL_Object.REMAIN; }
set { _SUMWHOUSE = value; }
}
private double _WHOUSE_SERIES;
public double WHOUSE_SERIES
{
get { return this._MTRL_Object.WHOUSE_SERIES_REMAIN; }
set { _WHOUSE_SERIES = value; }
}
private string _CODE1 = "";
public string CODE1
{
get { return this._MTRL_Object.CODE1; }
set { _CODE1 = value; }
}
private string _CODE2 = "";
public string CODE2
{
get { return this._MTRL_Object.CODE2; }
set { _CODE2 = value; }
}
private string _NAME = "";
public string NAME
{
get { return this._MTRL_Object.NAME; }
set { _NAME = value; }
}
private string _MTRL = "";
public string MTRL
{
get { return this._MTRL_Object.MTRL; }
set { _MTRL = value; }
}
private string _MTRUNIT1 = "";
public string MTRUNIT1
{
get
{
if (this._MTRL_Object.MTRUNIT1 != null)
return this._MTRL_Object.MTRUNIT1.name;
else
return "";
}
set { _MTRUNIT1 = value; }
}
private string _MTRUNIT2 = "";
public string MTRUNIT2
{
get
{
if (this._MTRL_Object.MTRUNIT2 != null)
return this._MTRL_Object.MTRUNIT2.name;
else
return "";
}
set { _MTRUNIT2 = value; }
}
private string _MTRUNIT3 = "";
public string MTRUNIT3
{
get
{
if (this._MTRL_Object.MTRUNIT3 != null)
return this._MTRL_Object.MTRUNIT3.name;
else
return "";
}
set { _MTRUNIT3 = value; }
}
private string _MTRUNIT4 = "";
public string MTRUNIT4
{
get
{
if (this._MTRL_Object.MTRUNIT4 != null)
return this._MTRL_Object.MTRUNIT4.name;
else
return "";
}
set { _MTRUNIT4 = value; }
}
private string _CRLOTCODE = "";
public string CRLOTCODE
{
get { return this._CRLOTCODE; }
set { _CRLOTCODE = value; }
}
private string _CRLOTCODE1 = "";
public string CRLOTCODE1
{
get { return this._CRLOTCODE1; }
set { _CRLOTCODE1 = value; }
}
private string _CRLOTCODE2 = "";
public string CRLOTCODE2
{
get { return this._CRLOTCODE2; }
set { _CRLOTCODE2 = value; }
}
private string _CRLOTFDATE = "";
public string CRLOTFDATE
{
get { return this._CRLOTFDATE; }
set { _CRLOTFDATE = value; }
}
private string _SCANEDCODE = "";
public string SCANEDCODE
{
get { return this._SCANEDCODE; }
set { _SCANEDCODE = value; }
}
private Thesi _WHOUSEBIN1_Object;
public Thesi WHOUSEBIN1_Object
{
get { return this._WHOUSEBIN1_Object; }
set { _WHOUSEBIN1_Object = value; }
}
private string _WHOUSEBIN1;
public string WHOUSEBIN1
{
get
{
if (this._WHOUSEBIN1_Object != null)
return this._WHOUSEBIN1_Object.name;
else
return "";
}
set { _WHOUSEBIN1 = value; }
}
private Thesi _WHOUSEBIN2_Object;
public Thesi WHOUSEBIN2_Object
{
get { return this._WHOUSEBIN2_Object; }
set { _WHOUSEBIN2_Object = value; }
}
private string _WHOUSEBIN2;
public string WHOUSEBIN2
{
get
{
if (this._WHOUSEBIN2_Object != null)
return this._WHOUSEBIN2_Object.name;
else
return "";
}
set { _WHOUSEBIN2 = value; }
}
private double _ANAMENOMENA;
public double ANAMENOMENA
{
get { return this._ANAMENOMENA; }
set { _ANAMENOMENA = value; }
}
private string _FINCODE = "";
public string FINCODE
{
get { return this._FINCODE; }
set { _FINCODE = value; }
}
private string _FINDOC = "";
public string FINDOC
{
get { return this._FINDOC; }
set { _FINDOC = value; }
}
private string _SODTYPE = "";
public string SODTYPE
{
get { return this._SODTYPE; }
set { _SODTYPE = value; }
}
private string _STATUS = "";
public string STATUS
{
get { return this._STATUS; }
set { _STATUS = value; }
}
private string _AA = "";
public string AA
{
get { return this._AA; }
set { _AA = value; }
}
private string _GUARANTY_SNCODE = "";
public string GUARANTY_SNCODE
{
get { return this._GUARANTY_SNCODE; }
set { _GUARANTY_SNCODE = value; }
}
}
I serialize it with the following code:
string data = Newtonsoft.Json.JsonConvert.SerializeObject(UniversalModel.Parastatiko,Formatting.None , new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore });
When I try to deserialize back to the object I get the exception error: ArgumentException.
The code to deserialize is this.
Findoc FFF = Newtonsoft.Json.JsonConvert.DeserializeObject<Findoc>(data, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore });
Any tips on what I am doing wrong?
It may just be a typo in the question but separating the Serializer arguments on to their own lines shows you are passing a UniversalModel.Parastatiko in as the first argument...which I don't think is correct.
string data = Newtonsoft.Json.JsonConvert.SerializeObject(
UniversalModel.Parastatiko,
Formatting.None,
new JsonSerializerSettings {
NullValueHandling = NullValueHandling.Ignore
}
);
private static int DefaultApiClientTimeout = 30;
public WorkItemDetail GetWorkItemDetail(
int userNumber, int userNumberExternal, string applicationId,
short computerNumber, DateTime wiDate, int wiSequence,
int wiDetailSequence, bool includeImage)
{
string uri = string.Format("api/work-item-detail?userNumber={0}&userNumberExternal={1}&applicationId={2}&computerNumber={3}&wiDate={4}&wiSequence={5}&wiDetailSequence={6}&includeImage={7}", userNumber, userNumberExternal, applicationId, computerNumber, wiDate, wiSequence, wiDetailSequence, includeImage);
WorkItemDetail result = ProcessRequest<object, WorkItemDetail>(uri, "GET", null);
return result;
}
public ResponseType ProcessRequest<RequestType, ResponseType>(
string uri,
string method = "GET",
RequestType reqtype = default(RequestType))
where RequestType : new()
{
var result = ProcessRequest<RequestType>(uri, method, reqtype);
return JsonConvert.DeserializeObject<ResponseType>(result);
}
public string ProcessRequest<RequestType>(
string uri,
string method = "GET",
RequestType reqtype = default(RequestType))
where RequestType : new()
{
var request = CreateWebRequest(uri, method);
var x = (HttpWebResponse)request.GetResponse(); //the exception :(
var strResult = new StreamReader(x.GetResponseStream()).ReadToEnd();
return strResult;
}
public WebRequest CreateWebRequest(string uri, string method = "GET")
{
string url = "http://localhost:3144/" + uri;
var request = WebRequest.Create(url);
request.ContentType = "application/json; charset=utf-8";
request.Method = method;
//Convert minutes to milliseconds.
request.Timeout = DefaultApiClientTimeout * 60000;
return request;
}
above is my entire code.
I have a problem in deserialzing jsondata. from my web api method data is returning correctly but when coming to client result i.e., above code while deserializing jsondata ImageInBytes property is getting null.
[Serializable]
public class WorkItemDetail : IWorkItemKey
{
private byte[] thumbnailImage;
private byte[] image;
private short wiDetailSequence;
private string workItemDetailType;
private int networkShare;
private string networkSharePath;
private string filePath;
private string displayImageFileName;
private string imagePath;
private DateTime workItemDate;
private string documentOcr;
#region Work Item Members
/// <summary>
/// This will actually be a ShortDate from the database
/// </summary>
public DateTime WorkItemDate
{
get { return workItemDate; }
set { workItemDate = value; }
}
private int wiSequence;
public int WISequence
{
get { return wiSequence; }
set { wiSequence = value; }
}
public short WIDetailSequence
{
get { return wiDetailSequence; }
set { wiDetailSequence = value; }
}
private short _otherSideWIDetailSequence;
public short OtherSideWIDetailSequence
{
get { return _otherSideWIDetailSequence; }
set { _otherSideWIDetailSequence = value; }
}
private string sourceType;
public string SourceType
{
get { return sourceType; }
set { sourceType = value; }
}
private string sourceIdentifier;
public string SourceIdentifier
{
get { return sourceIdentifier; }
set { sourceIdentifier = value; }
}
#endregion
private int _reason;
public int Reason
{
get { return _reason; }
set { _reason = value; }
}
private short _computerNumber;
public short ComputerNumber
{
get { return _computerNumber; }
set { _computerNumber = value; }
}
private string _computerName;
public string ComputerName
{
get { return _computerName; }
set { _computerName = value; }
}
private DateTime? _WIDateDest;
public DateTime? WIDateDest
{
get { return _WIDateDest; }
set { _WIDateDest = value; }
}
private int? _WISequenceDest;
public int? WISequenceDest
{
get { return _WISequenceDest; }
set { _WISequenceDest = value; }
}
private short? _WIDetailSequenceDest;
public short? WIDetailSequenceDest
{
get { return _WIDetailSequenceDest; }
set { _WIDetailSequenceDest = value; }
}
private short? _OtherSideWIDetailSequenceDest;
public short? OtherSideWIDetailSequenceDest
{
get { return _OtherSideWIDetailSequenceDest; }
set { _OtherSideWIDetailSequenceDest = value; }
}
public string WorkItemDetailType
{
get { return workItemDetailType; }
set { workItemDetailType = value; }
}
public int NetworkShare
{
get { return networkShare; }
set { networkShare = value; }
}
public string NetworkSharePath
{
get { return networkSharePath; }
set { networkSharePath = value; }
}
public string FilePath
{
get { return filePath; }
set { filePath = value; }
}
public string DisplayImageFileName
{
get { return displayImageFileName; }
set { displayImageFileName = value; }
}
public string ImagePath
{
get { return imagePath; }
set { imagePath = value; }
}
public byte[] ImageInBytes
{
get { return image; }
set { image = value; }
}
public byte[] ThumbnailImage
{
get { return thumbnailImage; }
set { thumbnailImage = value; }
}
private string ocrData;
public string OCRData
{
get { return ocrData; }
set { ocrData = value; }
}
private string _userName;
public string UserName
{
get { return _userName; }
set { _userName = value; }
}
private bool? _isCorrespondence;
public bool? IsCorrespondence
{
get { return _isCorrespondence; }
set { _isCorrespondence = value; }
}
private bool? isCorrespondenceDBValue;
public bool? IsCorrespondenceDBValue
{
get { return isCorrespondenceDBValue; }
set { isCorrespondenceDBValue = value; }
}
private Guid? wfInstanceId;
public Guid? WFInstanceId
{
get { return wfInstanceId; }
set { wfInstanceId = value; }
}
private DateTime _transactionTime;
public DateTime TransactionTime
{
get { return _transactionTime; }
set { _transactionTime = value; }
}
private DateTime _endTime;
public DateTime EndTime
{
get { return _endTime; }
set { _endTime = value; }
}
private string _transactionType;
public string TransactionType
{
get { return _transactionType; }
set { _transactionType = value; }
}
private string _applicationId;
public string ApplicationId
{
get { return _applicationId; }
set { _applicationId = value; }
}
private string _applicationName;
public string ApplicationName
{
get { return _applicationName; }
set { _applicationName = value; }
}
private bool isFront;
public bool IsFront
{
get { return isFront; }
set { isFront = value; }
}
private int _userNumber;
public int UserNumber
{
get { return _userNumber; }
set { _userNumber = value; }
}
private string barcode1;
public string BarCode1
{
get { return barcode1; }
set { barcode1 = value; }
}
private string barcode2;
public string BarCode2
{
get { return barcode2; }
set { barcode2 = value; }
}
private string barcode3;
public string BarCode3
{
get { return barcode3; }
set { barcode3 = value; }
}
private string barcode4;
public string BarCode4
{
get { return barcode4; }
set { barcode4 = value; }
}
private string barcode5;
public string BarCode5
{
get { return barcode5; }
set { barcode5 = value; }
}
private bool? markSense1;
public bool? MarkSense1
{
get { return markSense1; }
set { markSense1 = value; }
}
private bool? markSense2;
public bool? MarkSense2
{
get { return markSense2; }
set { markSense2 = value; }
}
private bool? markSense3;
public bool? MarkSense3
{
get { return markSense3; }
set { markSense3 = value; }
}
private bool? markSense4;
public bool? MarkSense4
{
get { return markSense4; }
set { markSense4 = value; }
}
private bool? markSense5;
public bool? MarkSense5
{
get { return markSense5; }
set { markSense5 = value; }
}
private bool? markSense6;
public bool? MarkSense6
{
get { return markSense6; }
set { markSense6 = value; }
}
private bool? markSense7;
public bool? MarkSense7
{
get { return markSense7; }
set { markSense7 = value; }
}
private bool? markSense8;
public bool? MarkSense8
{
get { return markSense8; }
set { markSense8 = value; }
}
private bool? markSense9;
public bool? MarkSense9
{
get { return markSense9; }
set { markSense9 = value; }
}
private bool? markSense10;
public bool? MarkSense10
{
get { return markSense10; }
set { markSense10 = value; }
}
private string data;
public string Data
{
get { return data; }
set { data = value; }
}
private string auditTrail;
public string AuditTrail
{
get { return auditTrail; }
set { auditTrail = value; }
}
private short? displayImageHorizontalPixels;
public short? DisplayImageHorizontalPixels
{
get { return displayImageHorizontalPixels; }
set { displayImageHorizontalPixels = value; }
}
private short? displayImageVerticalPixels;
public short? DisplayImageVerticalPixels
{
get { return displayImageVerticalPixels; }
set { displayImageVerticalPixels = value; }
}
private short? displayImageHorizontalResolution;
public short? DisplayImageHorizontalResolution
{
get { return displayImageHorizontalResolution; }
set { displayImageHorizontalResolution = value; }
}
private short? displayImageVerticalResolution;
public short? DisplayImageVerticalResolution
{
get { return displayImageVerticalResolution; }
set { displayImageVerticalResolution = value; }
}
private byte? displayImageColorDepth;
public byte? DisplayImageColorDepth
{
get { return displayImageColorDepth; }
set { displayImageColorDepth = value; }
}
private int displayImageBytes;
public int DisplayImageBytes
{
get { return displayImageBytes; }
set { displayImageBytes = value; }
}
private byte[] displayImageMD5Hash;
public byte[] DisplayImageMD5Hash
{
get { return displayImageMD5Hash; }
set { displayImageMD5Hash = value; }
}
private string iclImageFileName;
public string ICLImageFileName
{
get { return iclImageFileName; }
set { iclImageFileName = value; }
}
private short? iCLImageHorizontalPixels;
public short? ICLImageHorizontalPixels
{
get { return iCLImageHorizontalPixels; }
set { iCLImageHorizontalPixels = value; }
}
private short? iCLImageVerticalPixels;
public short? ICLImageVerticalPixels
{
get { return iCLImageVerticalPixels; }
set { iCLImageVerticalPixels = value; }
}
private short? iCLImageHorizontalResolution;
public short? ICLImageHorizontalResolution
{
get { return iCLImageHorizontalResolution; }
set { iCLImageHorizontalResolution = value; }
}
private short? iCLImageVerticalResolution;
public short? ICLImageVerticalResolution
{
get { return iCLImageVerticalResolution; }
set { iCLImageVerticalResolution = value; }
}
private byte? iCLImageColorDepth;
public byte? ICLImageColorDepth
{
get { return iCLImageColorDepth; }
set { iCLImageColorDepth = value; }
}
private int iCLImageBytes;
public int ICLImageBytes
{
get { return iCLImageBytes; }
set { iCLImageBytes = value; }
}
private byte[] iCLImageMD5Hash;
public byte[] ICLImageMD5Hash
{
get { return iCLImageMD5Hash; }
set { iCLImageMD5Hash = value; }
}
private string preparedFilePath;
public string PreparedFilePath
{
get { return preparedFilePath; }
set { preparedFilePath = value; }
}
private string displayImageFullPath;
public string DisplayImageFullPath
{
get { return displayImageFullPath; }
set { displayImageFullPath = value; }
}
/// <summary>
/// The results of full page OCR for this image, if available. This field may
/// not always be populated depending on the service method invoked and/or configuration
/// of document OCR for the particular site.
/// </summary>
public string DocumentOcr
{
get { return documentOcr; }
set { documentOcr = value; }
}
private OcrDataRecord _ocrrecord;
/// <summary>
/// Fully parsed ocr data.
/// </summary>
public OcrDataRecord OcrRecord
{
get { return _ocrrecord; }
set { _ocrrecord = value; }
}
private string _workItemLogNote;
public string WorkItemLogNote
{
get { return _workItemLogNote; }
set { _workItemLogNote = value; }
}
private bool _isDeleted;
public bool IsDeleted
{
get { return _isDeleted; }
set { _isDeleted = value; }
}
public override string ToString()
{
return string.Format("WIDate: {0} ,WISequence: {1}, WIDetailSequence: {2}, WIDetailType: {3}",
WorkItemDate.ToShortDateString(), WISequence, WIDetailSequence, WorkItemDetailType);
}
private DateTime? _batchStartDate;
public DateTime? BatchStartDate
{
get { return _batchStartDate; }
set { _batchStartDate = value; }
}
private short? _batchSeqNum;
public short? BatchSeqNum
{
get { return _batchSeqNum; }
set { _batchSeqNum = value; }
}
private short? _envelopeSequence;
public short? EnvelopeSequence
{
get { return _envelopeSequence; }
set { _envelopeSequence = value; }
}
}
other code to return
public async Task<WorkItemDetail> GetWorkItemDetailAsync(int userNumber, int userNumberExternal, string applicationId, short computerNumber, DateTime wiDate, int wiSequence, int wiDetailSequence, bool includeImage)
{
using (HttpClient client = base.CreateHttpClient())
{
WorkItemDetail workitemdetail = new WorkItemDetail();
var service_result = await client.GetAsync(string.Format("api/work-item-detail?userNumber={0}&userNumberExternal={1}&applicationId={2}&computerNumber={3}&wiDate={4}&wiSequence={5}&wiDetailSequence={6}&includeImage={7}", userNumber, userNumberExternal, applicationId, computerNumber, wiDate, wiSequence, wiDetailSequence, includeImage));
await ValidateResponseAsync(service_result);
workitemdetail = await service_result.Content.ReadAsAsync<WorkItemDetail>();
return workitemdetail;
}
}
I am trying to reach a foreach but my program never gets inside because my ICollection Coletores is always empty even if I put a lot of stuff in there.
The code where I want to get inside and it is always empty (I want to get inside the second foreach):
protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
{
if (NavigationContext.QueryString.TryGetValue("email", out email))
{
//MessageBox.Show(email);
List<HyperlinkButton> listaLinks = new List<HyperlinkButton>();
AppDataContext db = new AppDataContext();
int i = 0;
HyperlinkButton aux = new HyperlinkButton();
foreach (Pessoa pessoa in db.Pessoas)
{
if (pessoa.Email == email)
{
foreach (Coletor coletor in pessoa.Coletores)
{
aux.Content = "Coletor " + (i + 1).ToString();
aux.FontSize = 24;
aux.NavigateUri = new Uri("/OcorrenciasPage.xaml?coletorId=" + coletor.Id.ToString(), UriKind.RelativeOrAbsolute);
listaLinks.Add(aux);
i++;
}
}
}
ListBox coletores = new ListBox();
coletores.ItemsSource = listaLinks;
stcList.Children.Add(coletores);
}
base.OnNavigatedTo(e);
}
Now the code that I am adding data:
if (txtLat.Text != "" && txtLong.Text != "" && rdNorte.IsChecked == true || rdSul.IsChecked == true && rdLeste.IsChecked == true || rdOeste.IsChecked == true)
{
foreach (var pessoa in db.Pessoas)
{
if (pessoa.Email == email)
{
pessoa.Coletores.Add(coletor);
}
}
db.Coletores.InsertOnSubmit(coletor);
db.SubmitChanges();
NavigationService.Navigate(new Uri("/ColetoresPage.xaml?email=" + email, UriKind.RelativeOrAbsolute));
}
Now, my Pessoa class:
public class Pessoa : INotifyPropertyChanged
{
private int _id;
[Column(IsDbGenerated = true, IsPrimaryKey = true)]
public int Id {
get { return _id;}
set { _id = value;
OnPropertyChanged("Id");
}
}
private string _nome;
[Column]
public string Nome
{
get { return _nome; }
set { _nome = value;
OnPropertyChanged("Nome");
}
}
private string _email;
[Column]
public string Email
{
get { return _email; }
set { _email = value;
OnPropertyChanged("Email");
}
}
private string _senha;
[Column]
public string Senha { get { return _senha; }
set { _senha = value;
OnPropertyChanged("Senha");
}
}
private string _profissao;
[Column]
public string Profissao { get { return _profissao; }
set { _profissao = value;
OnPropertyChanged("Profissao");
}
}
private int _idade;
[Column]
public int Idade { get { return _idade; }
set { _idade = value;
OnPropertyChanged("Idade");
}
}
private string _endereco;
[Column]
public string Endereco { get { return _endereco; }
set { _endereco = value;
OnPropertyChanged("Endereco");
}
}
private string _cidade;
[Column]
public string Cidade { get { return _cidade; }
set { _cidade = value;
OnPropertyChanged("Cidade");
}
}
private string _estado;
[Column]
public string Estado { get { return _estado; }
set { _estado = value;
OnPropertyChanged("Estado");
}
}
private EntitySet<Coletor> _coletores = new EntitySet<Coletor>();
[Association(Name = "FK_Coletores_PessoaColetores", Storage = "_coletores", ThisKey = "Id", OtherKey = "pessoaId")]
public ICollection<Coletor> Coletores
{
get { return _coletores; }
set { _coletores.Assign(value); }
}
private EntitySet<PessoaColetor> _pessoaColetores = new EntitySet<PessoaColetor>();
[Association(Name = "FK_PessoaColetores_Pessoas", Storage = "_pessoaColetores", OtherKey = "pessoaId", ThisKey = "Id")]
private ICollection<PessoaColetor> PessoaColetores
{
get { return _pessoaColetores; }
set { _pessoaColetores.Assign(value); }
}
public event PropertyChangedEventHandler PropertyChanged;
private void OnPropertyChanged(string name)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(name));
}
}
}
The Coletores property on the Pessoa class looks alright. There is also a PessoaColetores property. Are you sure there has been no confusion between the two? Especially with intellisense one might dot or tab the wrong one.
Have you put a break point on the line that actually adds coletors (second code snippet)? Maybe stuff is added to the wrong collection.
Cheers, B.