İhtiyacınızı gösteren bazı kodlar.
(
ToList()
kullanarak) sorgu çalıştırıldıktan sağlamak için gerekli olan sonucu elde etmek için. Bunu yapmanın en etkili yolu, sayfalama (bonus) eklemek ve
PageResult<>
nesnesini döndürmektir.
public PageResult<WebPoco> Get(ODataQueryOptions<WebPoco> queryOptions)
{
var data2 = DatabaseData();
//Create a set of ODataQueryOptions for the internal class
ODataModelBuilder modelBuilder = new ODataConventionModelBuilder();
modelBuilder.EntitySet<DatabasePoco>("DatabasePoco");
var context = new ODataQueryContext(
modelBuilder.GetEdmModel(), typeof(DatabasePoco));
var newOptions = new ODataQueryOptions<DatabasePoco>(context, Request);
var t = new ODataValidationSettings() { MaxTop = 25 };
var s = new ODataQuerySettings() { PageSize = 25 };
newOptions.Validate(t);
IEnumerable<DatabasePoco> results =
(IEnumerable<DatabasePoco>)newOptions.ApplyTo(data2, s);
int skip = newOptions.Skip == null ? 0 : newOptions.Skip.Value;
int take = newOptions.Top == null ? 25 : newOptions.Top.Value;
List<DatabasePoco> internalResults = results.Skip(skip).Take(take).ToList();
// map from DatabasePoco to WebPoco here:
List<WebPoco> webResults;
PageResult<WebPoco> page =
new PageResult<WebPoco>(
webResults, Request.GetNextPageLink(), Request.GetInlineCount());
return page;
}
İşte o sevmediği,
private IQueryable<DatabasePoco> DatabaseData()
{
return (
new DatabasePoco[] {
new DatabasePoco() { id = 1, name = "one", type = "a" },
new DatabasePoco() { id = 2, name = "two", type = "b" },
new DatabasePoco() { id = 3, name = "three", type = "c" },
new DatabasePoco() { id = 4, name = "four", type = "d" },
new DatabasePoco() { id = 5, name = "five", type = "e" },
new DatabasePoco() { id = 6, name = "six", type = "f" },
new DatabasePoco() { id = 7, name = "seven", type = "g" },
new DatabasePoco() { id = 8, name = "eight", type = "h" },
new DatabasePoco() { id = 9, name = "nine", type = "i" }
})
.AsQueryable();
}
Bu yaklaşımı beğendim, maalesef, eski bir db ile çalışıyorum ve aşağıdaki hatayı alıyorum ... Karmaşık x tipi, Z işletmesi aracılığıyla Y türünü ifade eder. Bu konuda Google'da bir şey bulamıyorum. Sadece bir dairesel ref veya bir şey potansiyelini gösteren olduğunu varsayabilir ... – Lenny
@Lenny - 'ToList()' db denkleminden kaldırmalıdır. Ama EF haritalarını bilen var mı ?! Proxy'ler, tembel yükleme vb. Ile ilgili herhangi bir şey olabilir. Hangi hat başarısız? – qujck
onay bunun ardından teşekkürler http://stackoverflow.com/questions/15438195/odata-exception-the-complex-type-webtools-order-refers-to-the-entity-type-web ... – Lenny