Dave Roger
asked on
Cannot implictly convert values
I am having some difficulty with creating a class and passing decimal, date, boolean and even some integer values to the class from my Domain Service in a Visual Studio 2010 C# Silverlight application. There are several articles on this subject on the net but they are currently above my knowledge of C# and WCF and I cannot find a single example that passes anything other than a string or an integer. For the most part I have that working but some of my integer values require a suffix of .Value and some do not. I am not sure why.
The class I am trying to create and use is defined as:
Class to be populated
public class pmEmployee
{
[Key]
public int id { get; set; }
[DataMember]
public string member_num { get; set; }
public string last_name { get; set; }
public string first_name { get; set; }
public string middle_name_or_initial { get; set; }
public string address1 {get; set; }
public string address2 { get; set; }
public string city { get; set; }
public string state { get; set; }
public string zip { get; set; }
public DateTime birth_date { get; set; }
public DateTime hire_date { get; set; }
public string home_phone { get; set; }
public string cell_phone { get; set; }
public string work_phone_and_extension { get; set; }
public string work_phone_extension { get; set; }
public string SSN { get; set; }
public string clock_num { get; set; }
public int local_id { get; set; }
public int site_id { get; set; }
public string email_address { get; set; }
public int member_status_id { get; set; }
public int member_type_id { get; set; }
public int member_job_title_id { get; set; }
public string Marital { get; set; }
public string sex { get; set; }
public string notes { get; set; }
public int race_type_id { get; set; }
public string urnumber { get; set; }
public string bad_address_ind { get; set; }
public int dues_rate_id { get; set; }
public decimal cope_contribution { get; set; }
public bool grievance_exists_ind { get; set; }
public decimal overage_amt {get; set; }
}
The Domain Service Iqueryable I am hacking away at is:
public IQueryable<pmEmployee> GetEmployee(int EMPID)
{
return from emp in ObjectContext.tblEmployees
where emp.id == EMPID
select new pmEmployee()
{
id = emp.id,
member_num = emp.member_num == null ? null : emp.member_num,
last_name = emp.last_name == null ? null : emp.last_name,
first_name = emp.first_name == null ? null : emp.first_name,
middle_name_or_initial = emp.middle_name_or_initial == null ? null : emp.middle_name_or_initial ,
address1 = emp.address1 == null ? null : emp.address1,
address2 = emp.address2 == null ? null : emp.address2,
city = emp.city == null ? null : emp.city,
state = emp.state == null ? null : emp.state,
zip = emp.zip == null ? null : emp.zip,
cell_phone = emp.cell_phone == null ? null : emp.cell_phone,
local_id = emp.local_id.Value,
home_phone = emp.home_phone == null ? null : emp.home_phone,
work_phone_and_extension = emp.work_phone_and_extensi on == null ? null : emp.work_phone_and_extensi on,
work_phone_extension = emp.work_phone_extension == null ? null : emp.work_phone_extension,
SSN = emp.SSN == null ? null : emp.SSN,
clock_num = emp.clock_num == null ? null : emp.clock_num,
site_id = emp.site_id.Value,
email_address = emp.email_address == null ? null : emp.email_address,
member_status_id = emp.member_status_id.Value ,
member_type_id = emp.member_type_id.Value,
// member_job_title_id = emp.member_job_title_id.Va lue,
Marital = emp.Marital == null ? null : emp.Marital,
sex = emp.sex == null ? null : emp.sex,
notes = emp.notes == null ? null : emp.notes,
//Bad race_type_id = emp.race_type_id.Value,
urnumber = emp.urnumber == null ? null : emp.urnumber,
bad_address_ind = emp.bad_address_ind == null ? null : emp.bad_address_ind,
// birth_date = (DateTime) emp.birth_date.Value,
// overage_amt = emp.overage_amt
// dues_rate_id = emp.dues_rate_id.Value,
};
}
// overage = double.Parse(emp.overage_a mt), CultureInfo.InvariantCultu re.NumberF ormat)
//
I am not sure why some of the integers which are commented out cause problems but when I add them bound to a grid the system goes off to never never land. The date, decimal and booleans. For instance if I hold the mouse over birthdate when it is not commented out it says:
DateTime? tblEmployee.birth_date
No metadata documentation available.
for overage_amt which is a decimal value in the original table I get the message:
Cannot implicitly convert type 'decimal?' to decimal. An explicit conversion exists (are you missing a cast)?
Please don't point me to microsoft articles on WCF I have read them all and do not understand them I am looking for help with my variables.
Thanks,
Larry
The class I am trying to create and use is defined as:
Class to be populated
public class pmEmployee
{
[Key]
public int id { get; set; }
[DataMember]
public string member_num { get; set; }
public string last_name { get; set; }
public string first_name { get; set; }
public string middle_name_or_initial { get; set; }
public string address1 {get; set; }
public string address2 { get; set; }
public string city { get; set; }
public string state { get; set; }
public string zip { get; set; }
public DateTime birth_date { get; set; }
public DateTime hire_date { get; set; }
public string home_phone { get; set; }
public string cell_phone { get; set; }
public string work_phone_and_extension { get; set; }
public string work_phone_extension { get; set; }
public string SSN { get; set; }
public string clock_num { get; set; }
public int local_id { get; set; }
public int site_id { get; set; }
public string email_address { get; set; }
public int member_status_id { get; set; }
public int member_type_id { get; set; }
public int member_job_title_id { get; set; }
public string Marital { get; set; }
public string sex { get; set; }
public string notes { get; set; }
public int race_type_id { get; set; }
public string urnumber { get; set; }
public string bad_address_ind { get; set; }
public int dues_rate_id { get; set; }
public decimal cope_contribution { get; set; }
public bool grievance_exists_ind { get; set; }
public decimal overage_amt {get; set; }
}
The Domain Service Iqueryable I am hacking away at is:
public IQueryable<pmEmployee> GetEmployee(int EMPID)
{
return from emp in ObjectContext.tblEmployees
where emp.id == EMPID
select new pmEmployee()
{
id = emp.id,
member_num = emp.member_num == null ? null : emp.member_num,
last_name = emp.last_name == null ? null : emp.last_name,
first_name = emp.first_name == null ? null : emp.first_name,
middle_name_or_initial = emp.middle_name_or_initial
address1 = emp.address1 == null ? null : emp.address1,
address2 = emp.address2 == null ? null : emp.address2,
city = emp.city == null ? null : emp.city,
state = emp.state == null ? null : emp.state,
zip = emp.zip == null ? null : emp.zip,
cell_phone = emp.cell_phone == null ? null : emp.cell_phone,
local_id = emp.local_id.Value,
home_phone = emp.home_phone == null ? null : emp.home_phone,
work_phone_and_extension = emp.work_phone_and_extensi
work_phone_extension = emp.work_phone_extension == null ? null : emp.work_phone_extension,
SSN = emp.SSN == null ? null : emp.SSN,
clock_num = emp.clock_num == null ? null : emp.clock_num,
site_id = emp.site_id.Value,
email_address = emp.email_address == null ? null : emp.email_address,
member_status_id = emp.member_status_id.Value
member_type_id = emp.member_type_id.Value,
// member_job_title_id = emp.member_job_title_id.Va
Marital = emp.Marital == null ? null : emp.Marital,
sex = emp.sex == null ? null : emp.sex,
notes = emp.notes == null ? null : emp.notes,
//Bad race_type_id = emp.race_type_id.Value,
urnumber = emp.urnumber == null ? null : emp.urnumber,
bad_address_ind = emp.bad_address_ind == null ? null : emp.bad_address_ind,
// birth_date = (DateTime) emp.birth_date.Value,
// overage_amt = emp.overage_amt
// dues_rate_id = emp.dues_rate_id.Value,
};
}
// overage = double.Parse(emp.overage_a
//
I am not sure why some of the integers which are commented out cause problems but when I add them bound to a grid the system goes off to never never land. The date, decimal and booleans. For instance if I hold the mouse over birthdate when it is not commented out it says:
DateTime? tblEmployee.birth_date
No metadata documentation available.
for overage_amt which is a decimal value in the original table I get the message:
Cannot implicitly convert type 'decimal?' to decimal. An explicit conversion exists (are you missing a cast)?
Please don't point me to microsoft articles on WCF I have read them all and do not understand them I am looking for help with my variables.
Thanks,
Larry
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi
Sorry for the inactivity on this question. Our testing got a little sidetracked with some other fires. We will follow up on this shortly.
Sorry for the inactivity on this question. Our testing got a little sidetracked with some other fires. We will follow up on this shortly.
ASKER
Hi,
We ran into enough other formatting issues that we bought ComponentOne's Silverlight Studio, which has a number of these formattting tools available.
We ran into enough other formatting issues that we bought ComponentOne's Silverlight Studio, which has a number of these formattting tools available.
public string? member_num { get; set; }