This question is locked. New answers and comments are not allowed.
Hi,
I have a model built in OpenAccess that I query primarily in Linq, going against SQL Azure.
Although I have a decent model, I built a small "QueryResult" class that I use primarily in a couple of cases where I return data from a stored procedure, rather than through Linq. This class primarily exists because I'd rather not deal with anonymous types at this time.
Here's the class. As you can see it just has a "holder" field for Item, which is whatever I'm querying, and the Amount of sales represented by that item.
So my stored proc queries all work fine. And this Linq query works fine as well:
However, this Linq query fails. You'd think it would be a meaningless change, but apparantly changing the Key to ToString() is wrong.
It generates this error:
Unable to cast object of type 'Telerik.OpenAccess.RT.QueryBuilderImp' to type 'OpenAccessRuntime.DataObjects.query.Node'.
Is this a procedure that I just should not be doing, or is this an issue with OpenAccess?
Thanks,
Chris
I have a model built in OpenAccess that I query primarily in Linq, going against SQL Azure.
Although I have a decent model, I built a small "QueryResult" class that I use primarily in a couple of cases where I return data from a stored procedure, rather than through Linq. This class primarily exists because I'd rather not deal with anonymous types at this time.
Here's the class. As you can see it just has a "holder" field for Item, which is whatever I'm querying, and the Amount of sales represented by that item.
public class QueryResult : IComparable<QueryResult> |
{ |
public string Item { get; set; } |
public decimal Amount { get; set; } |
public int CompareTo(QueryResult other) |
{ |
return -Amount.CompareTo(other.Amount); |
} |
} |
So my stored proc queries all work fine. And this Linq query works fine as well:
public List<QueryResult> TransactionsBySource(int accountId, DateTime start, DateTime end) |
{ |
var transactions = from t in Scope.Extent<Transaction>() |
where t.AccountId == accountId && t.TransactionDate > start && t.TransactionDate < end |
group t by t.Source into g |
select new QueryResult() { Item = g.Key, Amount = g.Sum(s => s.PaymentGross) }; |
List<QueryResult> results = transactions.ToList(); |
results.Sort(); |
return results; |
} |
However, this Linq query fails. You'd think it would be a meaningless change, but apparantly changing the Key to ToString() is wrong.
public List<QueryResult> TransactionsByYear(int accountId) |
{ |
var transactions = from t in Scope.Extent<Transaction>() |
where t.AccountId == accountId |
group t by t.Year into g |
select new QueryResult() { Item = g.Key.ToString(), Amount = g.Sum(s => s.PaymentGross) }; |
return transactions.ToList(); |
} |
It generates this error:
Unable to cast object of type 'Telerik.OpenAccess.RT.QueryBuilderImp' to type 'OpenAccessRuntime.DataObjects.query.Node'.
Is this a procedure that I just should not be doing, or is this an issue with OpenAccess?
Thanks,
Chris