Question regarding 1:1 relationships - self servicing and databinding

Posts   
 
    
KastroNYC
User
Posts: 96
Joined: 23-Jan-2006
# Posted on: 21-May-2006 09:12:48   

I've got alot of 1:1's setup in my data model i.e:

Employee

id PK Birthdate smalldatetime DateCreated datetime ContactInfoID FK not null

ContactInfo

contactinfoID FirstName varchar LastName varchar Address

Is there a way to automatically have access to the fields of all 1:1 required relationships (as indicated by the db model) through Employee when its instantiated and saved such as:


Dim emp As New EmployeeEntity
emp.FirstName = "Kas"
emp.LastName = "C"
emp.Save

I understand that I can access the properties of the ContactInfo entity through emp.ContactInfo such as emp.ContactInfo.FirstName, etc however the reason I would like to see the required 1:1 relationships flat is because it really eases the process of databinding. As I understand it complex databinding doesn't support expressions like <%# Bind("Employee.ContactInformation.FirstName") %>. Right now the only way I can make a web grid bound to an Employee which displays their ContactInfo is by creating a complex databinding expression like <%# GetFirstName(Eval("ContactInfoID")) %> and creating a matching method that will return the correct FirstName but i'm sure there has got to be a better way to do this.

What i'd like to do is use the FormView control to provide access to the Entity for inserting and updating a record but if I need to write a method like this for each property in every 1:1 relationship to make it work it just doesn't seem to be worth the effort. Any direction on this matter is greatly appreciated. Thanks.

-Kas

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39928
Joined: 17-Aug-2003
# Posted on: 21-May-2006 11:30:48   

Look in the 'Fields mapped onto related fields' feature in the entity editor simple_smile (it's there since 1.0.2005.1 btw simple_smile )

Frans Bouma | Lead developer LLBLGen Pro
KastroNYC
User
Posts: 96
Joined: 23-Jan-2006
# Posted on: 21-May-2006 21:54:26   

That's exactly what I was looking for, thanks!

Another question, any nice solution for binding sub entities using a gridview with the following type of schema:

Employee

EmployeeID PK ContactInfoID FK

ContactInfo

ContactInfoID PK FirstName LastName

ContactInfoTelephone (two field PK)

ContactInfoID TelephoneID

Telephone

TelephoneID ACode ThreeDigit FourDigit

Ideally the solution I would like to use is something simple like:


  <cc1:LLBLGenProDataSource ID="llbl1" runat="server"
            DataContainerType="EntityCollection" EntityCollectionTypeName="MyCode.CollectionClasses.EmployeeCollection, MyCode">
        </cc1:LLBLGenProDataSource>

<asp:GridView ID="grid1" runat="server" datasourceID="llbl1">
<asp:TemplateField HeaderText="Telephone">
<ItemTemplate>
<asp:Repeater ID="repeaterTelephone" runat="server" DataSource='<%# Eval("Telephone") %>'>
<ItemTemplate>
 <asp:Label ID="Phone" runat="server" Text='<% Eval("ACode") %>'></asp:Label>
</ItemTemplate>
</asp:Repeater>
</ItemTemplate>
</asp:TemplateField>

</asp:GridView>

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39928
Joined: 17-Aug-2003
# Posted on: 22-May-2006 11:45:42   

I'd do that the old-fashioned way (asp.net 1.x) : in an event handler of the internal repeater, because I assume what you suggested doesn't work? You can't specify a datamember? (and use the same datasource as the grid) ?

Frans Bouma | Lead developer LLBLGen Pro
KastroNYC
User
Posts: 96
Joined: 23-Jan-2006
# Posted on: 22-May-2006 22:05:31   

That's correct, I've been using custom methods in the binding expression. What I mention is what I envision as the "right way" to get it done but its not possible in .NET. Thanks for the help.

pilotboba
User
Posts: 434
Joined: 05-Aug-2005
# Posted on: 22-May-2006 22:25:36   

KastroNYC wrote:

That's correct, I've been using custom methods in the binding expression. What I mention is what I envision as the "right way" to get it done but its not possible in .NET. Thanks for the help.

Well, you just need a grid that supports multi-levels (hierarchy) like Infragistics or Component Art's. (If I understand what you are trying to do.)

BOb