C# tabanlı bir OData kaynağım var ve çalışmak için $ genişletme konusunda sorun yaşıyorum. StackOverFlow ile ilgili tüm mesajlar OData V4'e başvurmuyor gibi görünüyor çünkü OData V4'ün altında/uygulamasında bulunmayan birçok kontrolör metodu.
Sorunum: İki varlığım var Tablo1 ve Tablo 2, burada aralarında bire bir ilişki var. Tablo1, bu ilişkiyi kolaylaştırmak için FK Table2Id ile Tablo2 adında bir gezinme özelliğine sahiptir. Ben URL'yi gönderdiğinizde
[Serializable, DataContract]
public class Table1
{
[DataMember, Key]
public int Id { get; set }
[DataMember]
public Table2 Table2 { get; set; }
[DataMember, ForeignKey("Table2")]
public int Table2Id { get; set;}
}
[Serializable, DataContract]
public class Table2
{
[DataMember, Key]
public int Id { get; set }
public string Name { get; set;}
}
:
[EnableQuery]
public IHttpActionResult Get(ODataQueryOptions<Table1> queryOptions)
{
IQueryable result;
// validate the query.
try
{
queryOptions.Validate(_validationSettings);
var dataSet = container.Get().AsQueryable(); // I can see Table1.Table2 here
result = queryOptions.ApplyTo(dataSet); // result has list of Table1 with Table2 nav property
}
catch (ODataException ex)
{
throw new HttpRequestException(ex.Message);
}
return Ok(result, result.GetType());
}
protected IHttpActionResult Ok(object content, Type type)
{
Type resultType = typeof (OkNegotiatedContentResult<>).MakeGenericType(type);
return Activator.CreateInstance(resultType, content, this) as IHttpActionResult;
}
Bu ApplyTo döküm bağlı gözükmektedir:
İşteThe query specified in the URI is not valid. Could not find a property named 'Table2' on type 'System.Web.OData.Query.Expressions.SelectAllAndExpand_1OfTable1
benim denetleyicisi var:
http://localhost/OData4/api/Table1s?$expand=Table2
bir hata alıyorum sonuç olmayan bir Artık Tablo1 türü, ancak bunun için bir sarıcı. Ancak, yönteme atılan bir istisna olmadan, sorunun gerçekte nerede olduğunu anlayamıyorum.
nuGet paketi kullanıyorum 'Microsoft ASP.Net Web API 2.2. OData V4.0 'V5.9.0 için.