select distinct Culture from resources
in orm and with linq i use this function :
public IQueryable RetrieveCultures()
{
var query = (from q in scope.Extent<Resource>()
select new
{
q.Culture
}).Distinct();
return query;
}
and then i call this function to bind return values to RadComboBox like this :
protected void RadComboBoxCultures_ItemsRequested(object o, Telerik.Web.UI.RadComboBoxItemsRequestedEventArgs e)
{
RadComboBoxCultures.DataSource = resourceManager.RetrieveCultures();
RadComboBoxCultures.DataBind();
}
but i have this error :
Cannot implicitly convert type 'System.Linq.IQueryable<AnonymousType#1>' to 'System.Linq.IQueryable<EandE.Framework.Entities.Utilities.Resource>'. An explicit conversion exists (are you missing a cast?)
what is the right solution ? what is the right linq expression for distinct ? how can i do the right casting?
6 Answers, 1 is accepted
how can i get distinct ?
what is the right linq expression and how can i return my result set from function (what is the right cast to handle error that i tell above)?
is there any body to give me a sample function that return a result set that are dustinct ?
Maybe I don't understand your class structure in full, so sorry if it is so...But it seems like you try to bind to a Resource instance, eventhough what is returned from the query is a Culture (don't know if this is a class or a simple type) instance
Makes sense?
Regards
HG
i say my quesion in other side,
my Resource Class structure is like below :
[Telerik.OpenAccess.Persistent(IdentityField = "FId")]
public class Resource
{
private int FId;
private string FName;
private string FDefaultValue;
private string FValue;
private string FCulture;
private ModuleType FModuleType;
private ObjectType FObjectType;
private string FNote;
}
i need a function that return all culture as distinct,
my mean is ( select distinct Culture from Resource ) in TSql or ( (from q in db.Resource select new {q.Culture}).Distinct(); ) in Linq
and now my problem is :
a function with linq in open access that return distinct result set
Did you try the following:
public IQueryable RetrieveCultures()
{
var query = (from q in scope.Extent<Resource>()
select q.Culture).Distinct();
return query;
}
/HG
what can i do for this : ???
( select distinct Field1,Field2,.. from MyTable )
is there any body here to give me a function like above with linq in OpenAccess that return resault set ?
I will try to explain further then. See the sample below:
public List<object> GetUniqueCultures()
{
var q = (
from r in scope.Extent<Resource>()
select r.Culture)
.Distinct();
List<object> cultures = new List<object>();
foreach (var c in q)
{
cultures.Add(new { Culture = c });
}
return cultures;
}
The result of the above method you assign to your datasource like:
ComboBoxCultures.DataSource = GetUniqueCultures();
Does it make sense?
Regards
/HG
PS. You could also have a look in the "LinqDemonstrationProject" in the "Examples" folder within your OpenAccess installation directory, if you have not already done so.