PDA

View Full Version : [CLOSED] V2.0 question on Model Associations and HasManyAssociation



Aurelio
Mar 25, 2012, 3:17 AM
Hi, could you help me to be explained on the command or property (?) and a small example of how you can use it to manage relationships :



<Associations>
<ext:HasManyAssociation ... ??/>
</Associations>


I read something in the documentation for extjs, but I can not understand how it works.

I have two table, "Clients" & "Orders", it's possible load a gridpanel with clients ad the click on a row load the order of client use the "Association" without performing a second query to load the orders ?

Thanks for any response

Aurelio

Daniil
Mar 26, 2012, 10:02 AM
Hi,

We are working on the examples. Today-tomorrow they should appear in SVN. We will notice you.

Aurelio
Mar 26, 2012, 11:26 AM
Hi Daniil...
Ok ...thank you very much

Aurelio

Daniil
Mar 29, 2012, 10:04 PM
Vladimir has committed the changes.

Please update Ext.NET.

The examples are in Examples.Ext.NET, it's on GitHub:
https://github.com/extnet

Aurelio
Mar 30, 2012, 11:45 AM
Hi, Daniil
Thanks,tomorrow download the sample and test.

Aurelio

Aurelio
Apr 05, 2012, 12:29 PM
Hi, thanks for the sample. I tried to make an example but I can not make it work, could you help me?
I have two Table Parent (Table PROVINCE) & Child (Table CAPCOM), i load the Store whit this linq query:



var database = new DataClassesARWebRevolutionDataContext();
Store1.DataSource = database.PROVINCE.Where(row => row.ProId < 3).Select(row => new
{
comuni = row.CAPCOM.ToList(),
row.ProId,
row.ProDes
});


The Store after the query content this data:
4078

I have define the grid :



<ext:GridPanel ID="GridPanel1"
runat="server"
Title="Province (seleziona una provincia per vedere i suoi comuni)"
Flex="1">
<Store>
<ext:Store ID="Store1" runat="server">
<Model>
<ext:Model ID="Model1" runat="server" Name="Province" IDProperty="ProId">
<Fields>
<ext:ModelField Name="ProId" Type="Int" />
<ext:ModelField Name="ProDes" Type="String" />
</Fields>
<Associations>
<ext:HasManyAssociation Model="Com" AssociationKey="comuni" Name="test" />
</Associations>
</ext:Model>
</Model>
</ext:Store>
</Store>
<ColumnModel>
<Columns>
<ext:Column ID="Column1" runat="server" Text="Provincia" DataIndex="ProDes" Flex="1" />
</Columns>
</ColumnModel>
<Listeners>
<SelectionChange Handler="selected.length && #{ProductsGrid}.bindStore(selected[0].test());" />
</Listeners>
</ext:GridPanel>
<ext:GridPanel
ID="ProductsGrid"
runat="server"
Title="Products"
Flex="1">
<Store>
<ext:Store runat="server">
<Model>
<ext:Model runat="server" Name="Com" IDProperty="CapComId">
<Fields>
<ext:ModelField Name="CapComId" Type="Int" />
<ext:ModelField Name="CapComCom" Type="String" />
</Fields>
</ext:Model>
</Model>
</ext:Store>
</Store>
<ColumnModel>
<Columns>
<ext:Column ID="Column2" runat="server" Text="Comune" DataIndex="CapComCom" Flex="1" />
</Columns>
</ColumnModel>
</ext:GridPanel>


The GridPanel1 is load correctly, but the click on a row the 2 gridpanel not load the data.
I can not understand the problem..the store1 i think it is loaded correctly.

Thanks
Aurelio

Vladimir
Apr 05, 2012, 12:37 PM
Hi,

Do you have 'comuni' property in theserialized data?
Please show serialized data for Model1 (Province)?

AssociationKey="comuni" assumes that serialized data for Model1 has array property contains list of records for Com model

Aurelio
Apr 05, 2012, 12:45 PM
Hi, Vladimir

I have no idea how to do serialized the data, we have to study ..
Now I see how to serialize the data..

Thanks

Vladimir
Apr 05, 2012, 2:36 PM
Hi,

Please note that in the example Ext.Net.Examples\Examples\Associations\HasMany\Sim ple\Default.aspx (i guess that you investigated that sample)
we use Data property of a store, the difference between Data and DataSource that Data object is serialized completely (all properties) but DataSource object is serialized according defined model fields

Our class User has Products property and that property is serialized (even if it is not defined in fields) therefore we can use AssociationKey="Products"

Aurelio
Apr 05, 2012, 3:42 PM
Hi Vlidimir
Thanks, I look for how to serialize the result of a linq query, I think there is a way, I go to san google :)

Aurelio