locked
Ado.net Relation Database Query Mistake RRS feed

  • General discussion

  • when I use this code in a datalist datasource, that give me a mistake

    public static IEnumerable<diamondModel.Urunler> GetirUrunleribyaltKategoriid(int altkategoriid)

    {

    try

    {

    //Urun_AltKategori?$expand=Urunler&$filter=AltKategori/id eq 1

    DataServiceContext servisim = new DataServiceContext(Declarations.uri);

    DataServiceQuery<diamondModel.Urunler> sorgum = servisim.CreateQuery<diamondModel.Urunler>("Urun_AltKategori").AddQueryOption("$expand", "Urunler").AddQueryOption("$filter", "AltKategori/id eq 1");

    return sorgum.Execute();

    }

    catch (Exception)

    {

    return null;

     

     

    }

    }

    The closed type diamondModel.Urunler does not have a corresponding Urunler settable property.

    Satır 28:             var sonuc = Veriislem.GetirUrunleribyaltKategoriid(gelenCatID);
    Satır 29:             DataList1.DataSource = sonuc;
    Satır 30:             DataList1.DataBind();

    [InvalidOperationException: The closed type diamondModel.Urunler does not have a corresponding Urunler settable property.]
       System.Data.Services.Client.ClientType.GetProperty(String propertyName, Boolean ignoreMissingProperties) +136
       System.Data.Services.Client.AtomMaterializer.MaterializeDataValues(ClientType actualType, List`1 values, Boolean ignoreMissingProperties, DataServiceContext context) +161
       System.Data.Services.Client.AtomMaterializer.MaterializeResolvedEntry(AtomEntry entry) +227
       System.Data.Services.Client.AtomMaterializer.Materialize(AtomEntry entry, Type expectedEntryType) +52
       System.Data.Services.Client.AtomMaterializer.DirectMaterializePlan(AtomMaterializer materializer, AtomEntry entry, Type expectedEntryType) +42
       System.Data.Services.Client.ProjectionPlan.Run(AtomMaterializer materializer, AtomEntry entry, Type expectedType) +57
       System.Data.Services.Client.AtomMaterializer.Read() +217
       System.Data.Services.Client.MaterializeAtom.MoveNextInternal() +466
       System.Data.Services.Client.MaterializeAtom.MoveNext() +110
       System.Web.UI.WebControls.DataList.CreateControlHierarchy(Boolean useDataSource) +377
       System.Web.UI.WebControls.BaseDataList.OnDataBinding(EventArgs e) +54
       System.Web.UI.WebControls.BaseDataList.DataBind() +55
       _Default.listedoldur() in C:\Users\selcuk\Desktop\STORE\Default.aspx.cs:30
       _Default.Page_Load(Object sender, EventArgs e) in C:\Users\selcuk\Desktop\STORE\Default.aspx.cs:20
       System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +14
       System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +35
       System.Web.UI.Control.OnLoad(EventArgs e) +99
       System.Web.UI.Control.LoadRecursive() +50
       System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +627

    How can I write a query in relations table ?

    Thanks

     

    • Edited by beceri Saturday, January 30, 2010 7:43 PM
    Saturday, January 30, 2010 7:30 PM

All replies

  • Hi,

    Could you please share the exception type along with the callstack of the exception you're getting? If possible also post a simplified version of the dieamondModel.Urunler class (public members should be enough).

    Aside from that by just looking at your code I would venture a guess that you're mixing types. In your CreateQuery call you ask for entity set Urun_AltKategori but that specify that the query should return elements of type Urunrel. I'm guessing that entity set Urun_AltKategori has entities of some different type, right?
    The query "/Urun_AltKategori?$expand=Urunrel&$filter=AltKategori/id eq 1" returns entities from the Urun_AltKategory entiti set and their Urunrel navigation property will also be filled with the appropriate data (by default, nav properties are not loaded, the $expand=Urunrel tells the system to load that nav property).
    So the result of this query will be something like IEnumerable<Utun_AltKategori>.

    Thanks,
    Vitek Karas [MSFT]
    Saturday, January 30, 2010 7:40 PM
    Moderator
  • there are 3 class for this code


    AltKategori
    -------------
    +Scalar Properties
    id
    adi
    +Navigation
    Kategoriler
    Urun_AltKategorileri



    Urun_AltKategori ( this make for endless-endless relations)
    -------------------
    +Scalar Properties
    id
    +Navigation
    AltKategori
    Urunler


    Urunler
    ----------------
    id
    ...
    ...
    +Navigation
    Urun_AltKategori
    ...
    ...

    Saturday, January 30, 2010 7:56 PM
  • Thanks Vitek Karas
     My datalist code  like this This Eval fields is Urunler field

     

    <asp:DataList ID="DataList1" runat="server" Height="400px"

     

    RepeatColumns="4" Width="726px">

     

    <ItemTemplate>

     

    <asp:Image ID="Image2" runat="server" Height="75px"

     

    Width="98px" /> <%--ImageUrl='<%# Eval("Picture","~/DvdImages/{0}") %>'--%>

     

    <br />

     

    <asp:Label ID="Label1" runat="server" Text='<%# Eval("kod") %>'></asp:Label>

     

    <br />

     

    <asp:Label ID="Label2" runat="server" Text='<%# Eval("adi") %>'></asp:Label>

     

    <asp:LinkButton ID="LinkButton3" runat="server"

     

    CommandArgument='<%# Eval("id") %>' CommandName="ayrinti">ayrintilar</asp:LinkButton>

     

    <br />

     

    <br />

     

    </ItemTemplate>

     

    </asp:DataList>

    Saturday, January 30, 2010 7:59 PM
  • Hi,

    This confirms what I guessed above. You assume the query will return Urunrel results, but the way you wrote it, it will return Urun_AltKatergori results.

    Thanks
    Vitek Karas [MSFT]
    Saturday, January 30, 2010 8:10 PM
    Moderator
  • I don't know exactly how ASP.NET Eval works, maybe something like "Urunrel.kod" will work. You could also turn the IEnumerable<Urun_AltKategori> using .Select(u => u.Urunrel) into IEnumerable<Urunrel> and then your code should continue to work as is.

    Thanks,


    Vitek Karas [MSFT]
    Saturday, January 30, 2010 8:31 PM
    Moderator
  • public

     

    static IEnumerable<diamondModel.Urun_AltKategori> GetirUrunleribyaltKategoriid(int altkategoriid)

    {

     

    try

    {

     

    //Urun_AltKategori?$expand=Urunler&$filter=AltKategori/id eq 1

     

    DataServiceContext servisim = new DataServiceContext(Declarations.uri);

     

    DataServiceQuery<diamondModel.Urun_AltKategori> sorgum = servisim.CreateQuery<diamondModel.Urun_AltKategori>("Urun_AltKategori").AddQueryOption("$expand", "Urunler").AddQueryOption("$filter", "AltKategori/id eq 1");

     

    return sorgum.Execute();

    }

     

    catch (Exception)

    {

     

    return null;

    }

    }

     



    I change my code like this,

    But Now I take mistake DataBinding:

    'diamondModel.Urun_AltKategori', kod adında bir özellik içermiyor.
    (Urun_AltKategori has not a like this property)
    Satır 28:     Width="98px" /> <%--ImageUrl='<%# Eval("Picture","~/DvdImages/{0}") %>'--%>
    Satır 29:             <br />
    Satır 30:             <asp:Label ID="Label1" runat="server" Text='<%# Eval("kod") %>'></asp:Label>
    Satır 31:             <br />
    Satır 32:             <asp:Label ID="Label2" runat="server" Text='<%# Eval("adi") %>'></asp:Label>


    [HttpException (0x80004005): DataBinding: 'diamondModel.Urun_AltKategori', kod adında bir özellik içermiyor.]
       System.Web.UI.DataBinder.GetPropertyValue(Object container, String propName) +8661733
       System.Web.UI.DataBinder.Eval(Object container, String[] expressionParts) +92
       System.Web.UI.DataBinder.Eval(Object container, String expression) +106
       System.Web.UI.TemplateControl.Eval(String expression) +40
       ASP.default_aspx.__DataBinding__control4(Object sender, EventArgs e) in C:\Users\selcuk\Desktop\STORE\Default.aspx:30
       System.Web.UI.Control.OnDataBinding(EventArgs e) +99
       System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding) +92
       System.Web.UI.Control.DataBind() +15
       System.Web.UI.Control.DataBindChildren() +211
       System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding) +102
       System.Web.UI.Control.DataBind() +15
       System.Web.UI.WebControls.DataList.CreateItem(Int32 itemIndex, ListItemType itemType, Boolean dataBind, Object dataItem) +125
       System.Web.UI.WebControls.DataList.CreateControlHierarchy(Boolean useDataSource) +459
       System.Web.UI.WebControls.BaseDataList.OnDataBinding(EventArgs e) +54
       System.Web.UI.WebControls.BaseDataList.DataBind() +55
       _Default.listedoldur() in C:\Users\selcuk\Desktop\STORE\Default.aspx.cs:30
       _Default.Page_Load(Object sender, EventArgs e) in C:\Users\selcuk\Desktop\STORE\Default.aspx.cs:20
       System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +14
       System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +35
       System.Web.UI.Control.OnLoad(EventArgs e) +99
       System.Web.UI.Control.LoadRecursive() +50
       System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +627


    field is not Urun_AltKategori's field.Here Urun's field, How can I change datalist Databinding code ?
    thanks

    Saturday, January 30, 2010 8:33 PM
  • Thanks for helping

    Eval Urunler.kod is perfect running

    Thanks Vitek Karas Again and Again
    Saturday, January 30, 2010 9:00 PM