Reputation: 273
I have a room database that stores a list of vacation resorts, which includes fields for State and Country, and am trying to get a distinct list of the State/Country combinations.
So far I have:
@Query("SELECT DISTINCT state,country from ResortdatabaseModel")
List<StateModel> getAllStates();
However, StateModel is not an entity within the database, it's a model defined elsewhere in the project, and I'm getting an error "Not sure how to convert a Cursor to this method's return type "
How do I map the query results to the exiting model?
Upvotes: 0
Views: 179
Reputation: 16534
The class StateModel
needs to have the properties state
and country
with the same types as those two columns in Resortdatabasemodel
, e.g.:
data class StateModel(
val state: String,
val country: String,
)
(String
is just an example here, I don't know the actual types in your project)
Upvotes: 1