Sign In| Join
Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post May 13, 2011 03:44 AM by Jonathan Shen – MSFT
Member
20 Points
5 Posts
May 05, 2011 08:07 AM|LINK
I have two classes as User and Country. User class is having a property which is object of Country. User database table is having a CountryID column.
While Retrieving User Data as Objects it gives below error:
Invalid cast from 'System.Int32' to 'country'
which is true because data table is having int and class is expecting Object of country.
Below is the menthod which I am using:
public static IEnumerable<User> GetAllUsers()
{
IEnumerable<User> userData = null;
try
IRowMapper<User> mapper = MapBuilder<User>.BuildAllProperties();
Database Db = DatabaseFactory.CreateDatabase();
// Create a stored procedure accessor that uses this output mapper
var accessor = Db.CreateSprocAccessor("GetAllUsers", mapper);
// Execute the accessor to obtain the results
userData = accessor.Execute();
}
catch (Exception ex)
throw ex;
return userData;
I tried using MapAllProperties, does not help. Seems being a newbie missing something.
All-Star
31269 Points
3445 Posts
May 13, 2011 03:44 AM|LINK
Hi,
What's your issue going now?
Best regards,
Jonathan
tarunmangla
Member
20 Points
5 Posts
Retrieving Data as Objects
May 05, 2011 08:07 AM|LINK
I have two classes as User and Country. User class is having a property which is object of Country. User database table is having a CountryID column.
While Retrieving User Data as Objects it gives below error:
Invalid cast from 'System.Int32' to 'country'
which is true because data table is having int and class is expecting Object of country.
Below is the menthod which I am using:
public static IEnumerable<User> GetAllUsers()
{
IEnumerable<User> userData = null;
try
{
IRowMapper<User> mapper = MapBuilder<User>.BuildAllProperties();
Database Db = DatabaseFactory.CreateDatabase();
// Create a stored procedure accessor that uses this output mapper
var accessor = Db.CreateSprocAccessor("GetAllUsers", mapper);
// Execute the accessor to obtain the results
userData = accessor.Execute();
}
catch (Exception ex)
{
throw ex;
}
return userData;
}
I tried using MapAllProperties, does not help. Seems being a newbie missing something.
Jonathan She...
All-Star
31269 Points
3445 Posts
Re: Retrieving Data as Objects
May 13, 2011 03:44 AM|LINK
Hi,
What's your issue going now?
Best regards,
Jonathan
If you have any feedback about my replies, please contact msdnmg@microsoft.com.
Microsoft One Code Framework