DynamicData pages and additional fields on an EDM model

  • Thread starter Thread starter markla
  • Start date Start date
M

markla

Hi,

I have an EDM model, which I'm rendering using DynamicData pages.

I need to add a derived/calculated field.

For example, in a "Person" entity, I have LastName and FirstName. I need to
add a derived field FullName (being LastName + ", " + FirstName)

I have tried adding the FullName field to Person's EDM partial class, and
set the column to be scaffolded, however I can't get FullName to display.

Any tips on how to get derived fields to show in DynamicData pages?

Thanks,
+Mark
 
- Create a partial Class of your entity
- Add a Public ReadOnly Property for the compute column
- Add atrtribute ScaffoldColumnAttribute(True) to the Property

Atte. Elmer Carías
DCE 4
El Salvador , Central America
 
Hi Mark,

Due to current limitation of Entity Data Model we cannot achieve this by
adding a scaffold property in the partial class.

I have two suggestions for you that can work it around:

1. You can customize the page template. Please refer to this video:
http://www.asp.net/learn/3.5-sp1/video-293.aspx

You can set AutoGenerateColumns to true and add an extra column. Something
like this:
<asp:GridView AutoGenerateColumns="True" ID="GridView1" runat="server"
DataSourceID="GridDataSource"
AllowPaging="True" AllowSorting="True" CssClass="gridview">
<Columns>
<asp:TemplateField>
<HeaderTemplate>
FullName
</HeaderTemplate>
<ItemTemplate>
<%#Eval("FirstName").ToString() + "," +
Eval("LastName").ToString() %>
</ItemTemplate></asp:TemplateField>
<asp:TemplateField>

2. You can hide the LastName field and use a custom field template for the
FirstName field. To do this, Add a FullNameControl in the FieldTemplates
folder:

<%@ Control Language="C#" AutoEventWireup="true"
CodeBehind="FullNameControl.ascx.cs"
Inherits="DynamicAspNetTest.DynamicData.FieldTemplates.FullNameControl" %>
<asp:Literal runat="server" ID="Literal1" Text='<%#
Eval("FirstName").ToString() + "," + Eval("LastName").ToString() %>' />

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace DynamicAspNetTest.DynamicData.FieldTemplates
{
public partial class NameControl :
System.Web.DynamicData.FieldTemplateUserControl
{
public override Control DataControl
{
get
{
return Literal1;
}
}
}
}

Then edit your partial class:

[MetadataType(typeof(PersonMetadata))]
public partial class Person
{

}

public class PersonMetadata
{
//Show FullName in the FirstName column
[UIHint("FullNameControl")]
[DisplayName("FullName")]
public string FirstName { get; set; }

//Hide LastName
[ScaffoldColumn(false)]
public string LastName { get; set; }


}

Please have a try and feel free to ask if you have further questions.

Regards,
Allen Chen
Microsoft Online Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

--------------------
| From: "markla" <[email protected]>
| Subject: DynamicData pages and additional fields on an EDM model
| Date: Wed, 3 Sep 2008 02:51:54 -0400
| Lines: 1
| MIME-Version: 1.0
| Content-Type: text/plain;
| format=flowed;
| charset="iso-8859-1";
| reply-type=original
| Content-Transfer-Encoding: 7bit
| X-Priority: 3
| X-MSMail-Priority: Normal
| Importance: Normal
| X-Newsreader: Microsoft Windows Live Mail 12.0.1606
| X-MimeOLE: Produced By Microsoft MimeOLE V12.0.1606
| Message-ID: <[email protected]>
| Newsgroups:
microsoft.public.dotnet.framework.adonet,microsoft.public.dotnet.framework.a
spnet
| NNTP-Posting-Host: 12-50-98-79.att-inc.com 12.50.98.79
| Path: TK2MSFTNGHUB02.phx.gbl!TK2MSFTNGP01.phx.gbl!TK2MSFTNGP04.phx.gbl
| Xref: TK2MSFTNGHUB02.phx.gbl
microsoft.public.dotnet.framework.aspnet:75165
microsoft.public.dotnet.framework.adonet:11090
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
|
| Hi,
|
| I have an EDM model, which I'm rendering using DynamicData pages.
|
| I need to add a derived/calculated field.
|
| For example, in a "Person" entity, I have LastName and FirstName. I need
to
| add a derived field FullName (being LastName + ", " + FirstName)
|
| I have tried adding the FullName field to Person's EDM partial class, and
| set the column to be scaffolded, however I can't get FullName to display.
|
| Any tips on how to get derived fields to show in DynamicData pages?
|
| Thanks,
| +Mark
|
|
 
Thanks- unfortunately I still get the same error: "The display column
'FullName' specified for the table 'People' does not exist."

I'm using c#. Below is the code, for information. I've tried the
ScaffoldColumn attribute on the property, and in the metadata class, neither
make any difference.

Suggestions, anyone?

--->
[MetadataType(typeof(PersonMetadata))]
[ScaffoldTable(true)]
[DisplayColumn("FullName")]
[DisplayName("Person")]
public partial class Person
{
public string FullName
{
get
{
return this.LastName + ", " + this.FirstName;
}
}
}
public class PersonMetadata
{
[ScaffoldColumn(false)]
public string PersonId;

[ScaffoldColumn(true)]
public string FullName;
}
--->
 
Hi Mark,

If I'm correct you're using my second suggestion. To do this please try
following steps:

1. Add a new Web UserControl called FullNameControl.ascx in the
FieldTemplates folder. Here's the code:
ascx:
<%@ Control Language="C#" AutoEventWireup="true"
CodeBehind="FullNameControl.ascx.cs"
Inherits="DynamicAspNetTest.DynamicData.FieldTemplates.FullNameControl" %>
<asp:Literal runat="server" ID="Literal1" Text='<%#
Eval("FirstName").ToString() + "," + Eval("LastName").ToString() %>' />

ascx.cs:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace DynamicAspNetTest.DynamicData.FieldTemplates
{
public partial class NameControl :
System.Web.DynamicData.FieldTemplateUserControl
{
public override Control DataControl
{
get
{
return Literal1;
}
}
}
}

2. Edit the partial class:
[MetadataType(typeof(PersonMetadata))]
public partial class Person
{

}

public class PersonMetadata
{
//Show FullName in the FirstName column
[UIHint("FullNameControl")]
[DisplayName("FullName")]
public string FirstName { get; set; }

//Hide LastName
[ScaffoldColumn(false)]
public string LastName { get; set; }


}

Please note, the "FullName" only appears at [DisplayName("FullName")]. We
don't have to add a new property in the PersonMetadata calss. The idea is
to change the DisplayName of the FistName field and use a custom UI
(FullNameControl.ascx) to let it show the "FullName".

Please have a try and let me know if my code works.

Regards,
Allen Chen
Microsoft Online Support

--------------------
| From: "markla" <[email protected]>
| References: <[email protected]>
<#[email protected]>
| Subject: Re: DynamicData pages and additional fields on an EDM model
| Date: Fri, 5 Sep 2008 05:48:32 -0400
| Lines: 1
| MIME-Version: 1.0
| Content-Type: text/plain;
| format=flowed;
| charset="iso-8859-1";
| reply-type=response
| Content-Transfer-Encoding: 8bit
| X-Priority: 3
| X-MSMail-Priority: Normal
| Importance: Normal
| X-Newsreader: Microsoft Windows Live Mail 12.0.1606
| X-MimeOLE: Produced By Microsoft MimeOLE V12.0.1606
| Message-ID: <[email protected]>
| Newsgroups:
microsoft.public.dotnet.framework.adonet,microsoft.public.dotnet.framework.a
spnet
| NNTP-Posting-Host: 12-50-98-46.att-inc.com 12.50.98.46
| Path: TK2MSFTNGHUB02.phx.gbl!TK2MSFTNGP01.phx.gbl!TK2MSFTNGP04.phx.gbl
| Xref: TK2MSFTNGHUB02.phx.gbl
microsoft.public.dotnet.framework.aspnet:75318
microsoft.public.dotnet.framework.adonet:11114
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
|
| Thanks- unfortunately I still get the same error: "The display column
| 'FullName' specified for the table 'People' does not exist."
|
| I'm using c#. Below is the code, for information. I've tried the
| ScaffoldColumn attribute on the property, and in the metadata class,
neither
| make any difference.
|
| Suggestions, anyone?
|
| --->
| [MetadataType(typeof(PersonMetadata))]
| [ScaffoldTable(true)]
| [DisplayColumn("FullName")]
| [DisplayName("Person")]
| public partial class Person
| {
| public string FullName
| {
| get
| {
| return this.LastName + ", " + this.FirstName;
| }
| }
| }
| public class PersonMetadata
| {
| [ScaffoldColumn(false)]
| public string PersonId;
|
| [ScaffoldColumn(true)]
| public string FullName;
| }
| --->
|
| | > - Create a partial Class of your entity
| > - Add a Public ReadOnly Property for the compute column
| > - Add atrtribute ScaffoldColumnAttribute(True) to the Property
| >
| > Atte. Elmer Carías
| > DCE 4
| > El Salvador , Central America
| >
| >
| >
| > "markla" <[email protected]> escribió en el mensaje
| > | >> Hi,
| >>
| >> I have an EDM model, which I'm rendering using DynamicData pages.
| >>
| >> I need to add a derived/calculated field.
| >>
| >> For example, in a "Person" entity, I have LastName and FirstName. I
need
| >> to add a derived field FullName (being LastName + ", " + FirstName)
| >>
| >> I have tried adding the FullName field to Person's EDM partial class,
and
| >> set the column to be scaffolded, however I can't get FullName to
display.
| >>
| >> Any tips on how to get derived fields to show in DynamicData pages?
| >>
| >> Thanks,
| >> +Mark
| >
| >
|
 
Hi Mark,

Have you tried my suggestion? Can my code work?

Regards,
Allen Chen
Microsoft Online Community Support
--------------------
| From: "markla" <[email protected]>
| References: <[email protected]>
<#[email protected]>
| Subject: Re: DynamicData pages and additional fields on an EDM model
| Date: Fri, 5 Sep 2008 05:48:32 -0400
| Lines: 1
| MIME-Version: 1.0
| Content-Type: text/plain;
| format=flowed;
| charset="iso-8859-1";
| reply-type=response
| Content-Transfer-Encoding: 8bit
| X-Priority: 3
| X-MSMail-Priority: Normal
| Importance: Normal
| X-Newsreader: Microsoft Windows Live Mail 12.0.1606
| X-MimeOLE: Produced By Microsoft MimeOLE V12.0.1606
| Message-ID: <[email protected]>
| Newsgroups:
microsoft.public.dotnet.framework.adonet,microsoft.public.dotnet.framework.a
spnet
| NNTP-Posting-Host: 12-50-98-46.att-inc.com 12.50.98.46
| Path: TK2MSFTNGHUB02.phx.gbl!TK2MSFTNGP01.phx.gbl!TK2MSFTNGP04.phx.gbl
| Xref: TK2MSFTNGHUB02.phx.gbl
microsoft.public.dotnet.framework.aspnet:75318
microsoft.public.dotnet.framework.adonet:11114
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
|
| Thanks- unfortunately I still get the same error: "The display column
| 'FullName' specified for the table 'People' does not exist."
|
| I'm using c#. Below is the code, for information. I've tried the
| ScaffoldColumn attribute on the property, and in the metadata class,
neither
| make any difference.
|
| Suggestions, anyone?
|
| --->
| [MetadataType(typeof(PersonMetadata))]
| [ScaffoldTable(true)]
| [DisplayColumn("FullName")]
| [DisplayName("Person")]
| public partial class Person
| {
| public string FullName
| {
| get
| {
| return this.LastName + ", " + this.FirstName;
| }
| }
| }
| public class PersonMetadata
| {
| [ScaffoldColumn(false)]
| public string PersonId;
|
| [ScaffoldColumn(true)]
| public string FullName;
| }
| --->
|
| | > - Create a partial Class of your entity
| > - Add a Public ReadOnly Property for the compute column
| > - Add atrtribute ScaffoldColumnAttribute(True) to the Property
| >
| > Atte. Elmer Carías
| > DCE 4
| > El Salvador , Central America
| >
| >
| >
| > "markla" <[email protected]> escribió en el mensaje
| > | >> Hi,
| >>
| >> I have an EDM model, which I'm rendering using DynamicData pages.
| >>
| >> I need to add a derived/calculated field.
| >>
| >> For example, in a "Person" entity, I have LastName and FirstName. I
need
| >> to add a derived field FullName (being LastName + ", " + FirstName)
| >>
| >> I have tried adding the FullName field to Person's EDM partial class,
and
| >> set the column to be scaffolded, however I can't get FullName to
display.
| >>
| >> Any tips on how to get derived fields to show in DynamicData pages?
| >>
| >> Thanks,
| >> +Mark
| >
| >
|
 
Thanks- the code works for displaying a "person".

However, the other half of the problem, is how I display the fullname in a
related table. Let's say the person has an Entry into a competition, so for
an Entry there is a PersonId, a CompId, and a TicketNumber field. When I
display a list of entries for a competition, I need to display the fullname,
as a combination of both FirstName and LastName.

I can't see an obvious way to modify the ForeignKey.ascx class to lookup two
fields from the parent entity- it only gets the "GetDisplayString()"- which
is returned based on the [DisplayColumn()] attribute of the Person class-
and I can only specify individual fields in DisplayColumn().

How can I show the FullName for each related parent person in a list?

Thanks,
+Mark

Allen Chen said:
Hi Mark,

If I'm correct you're using my second suggestion. To do this please try
following steps:

1. Add a new Web UserControl called FullNameControl.ascx in the
FieldTemplates folder. Here's the code:
ascx:
<%@ Control Language="C#" AutoEventWireup="true"
CodeBehind="FullNameControl.ascx.cs"
Inherits="DynamicAspNetTest.DynamicData.FieldTemplates.FullNameControl" %>
<asp:Literal runat="server" ID="Literal1" Text='<%#
Eval("FirstName").ToString() + "," + Eval("LastName").ToString() %>' />

ascx.cs:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace DynamicAspNetTest.DynamicData.FieldTemplates
{
public partial class NameControl :
System.Web.DynamicData.FieldTemplateUserControl
{
public override Control DataControl
{
get
{
return Literal1;
}
}
}
}

2. Edit the partial class:
[MetadataType(typeof(PersonMetadata))]
public partial class Person
{

}

public class PersonMetadata
{
//Show FullName in the FirstName column
[UIHint("FullNameControl")]
[DisplayName("FullName")]
public string FirstName { get; set; }

//Hide LastName
[ScaffoldColumn(false)]
public string LastName { get; set; }


}

Please note, the "FullName" only appears at [DisplayName("FullName")]. We
don't have to add a new property in the PersonMetadata calss. The idea is
to change the DisplayName of the FistName field and use a custom UI
(FullNameControl.ascx) to let it show the "FullName".

Please have a try and let me know if my code works.

Regards,
Allen Chen
Microsoft Online Support

--------------------
| From: "markla" <[email protected]>
| References: <[email protected]>
<#[email protected]>
| Subject: Re: DynamicData pages and additional fields on an EDM model
| Date: Fri, 5 Sep 2008 05:48:32 -0400
| Lines: 1
| MIME-Version: 1.0
| Content-Type: text/plain;
| format=flowed;
| charset="iso-8859-1";
| reply-type=response
| Content-Transfer-Encoding: 8bit
| X-Priority: 3
| X-MSMail-Priority: Normal
| Importance: Normal
| X-Newsreader: Microsoft Windows Live Mail 12.0.1606
| X-MimeOLE: Produced By Microsoft MimeOLE V12.0.1606
| Message-ID: <[email protected]>
| Newsgroups:
microsoft.public.dotnet.framework.adonet,microsoft.public.dotnet.framework.a
spnet
| NNTP-Posting-Host: 12-50-98-46.att-inc.com 12.50.98.46
| Path: TK2MSFTNGHUB02.phx.gbl!TK2MSFTNGP01.phx.gbl!TK2MSFTNGP04.phx.gbl
| Xref: TK2MSFTNGHUB02.phx.gbl
microsoft.public.dotnet.framework.aspnet:75318
microsoft.public.dotnet.framework.adonet:11114
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
|
| Thanks- unfortunately I still get the same error: "The display column
| 'FullName' specified for the table 'People' does not exist."
|
| I'm using c#. Below is the code, for information. I've tried the
| ScaffoldColumn attribute on the property, and in the metadata class,
neither
| make any difference.
|
| Suggestions, anyone?
|
| --->
| [MetadataType(typeof(PersonMetadata))]
| [ScaffoldTable(true)]
| [DisplayColumn("FullName")]
| [DisplayName("Person")]
| public partial class Person
| {
| public string FullName
| {
| get
| {
| return this.LastName + ", " + this.FirstName;
| }
| }
| }
| public class PersonMetadata
| {
| [ScaffoldColumn(false)]
| public string PersonId;
|
| [ScaffoldColumn(true)]
| public string FullName;
| }
| --->
|
| | > - Create a partial Class of your entity
| > - Add a Public ReadOnly Property for the compute column
| > - Add atrtribute ScaffoldColumnAttribute(True) to the Property
| >
| > Atte. Elmer Carías
| > DCE 4
| > El Salvador , Central America
| >
| >
| >
| > "markla" <[email protected]> escribió en el mensaje
| > | >> Hi,
| >>
| >> I have an EDM model, which I'm rendering using DynamicData pages.
| >>
| >> I need to add a derived/calculated field.
| >>
| >> For example, in a "Person" entity, I have LastName and FirstName. I
need
| >> to add a derived field FullName (being LastName + ", " + FirstName)
| >>
| >> I have tried adding the FullName field to Person's EDM partial class,
and
| >> set the column to be scaffolded, however I can't get FullName to
display.
| >>
| >> Any tips on how to get derived fields to show in DynamicData pages?
| >>
| >> Thanks,
| >> +Mark
| >
| >
|
 
Hi Mark,
We can use a similar approach to achieve this for the Competition table.

1. Firstly add a Web User Control MyForeignKey.ascx in the FieldTemplates
folder:

ascx:
<%@ Control Language="C#" AutoEventWireup="true"
CodeBehind="MyForeignKey.ascx.cs"
Inherits="DynamicAspNetTest.DynamicData.FieldTemplates.MyForeignKey" %>
<asp:Literal runat="server" ID="Literal1" Text="<%# GetDisplayString() %>"/>

ascx.cs:
public partial class MyForeignKey :
System.Web.DynamicData.FieldTemplateUserControl
{
public override Control DataControl
{
get
{

return Literal1;
}
}
protected string GetDisplayString()
{
Person p=(Person)FieldValue;
string fullname= p.FirstName + "," + p.LastName;
return fullname;
}
}

2. Edit the partial class:
[MetadataType(typeof(CompetitionHeaderMetadata))]
public partial class Competition
{

}
public class CompetitionHeaderMetadata
{

[UIHint("MyForeignKey")]
public Customer Customer { get; set; }

}

Please try it and let me know if it works.

Thanks,
Allen Chen
Microsoft Online Support

--------------------
| From: "markla" <[email protected]>
| References: <[email protected]>
<#[email protected]>
<[email protected]>
<[email protected]>
| Subject: Re: DynamicData pages and additional fields on an EDM model
| Date: Wed, 10 Sep 2008 11:31:10 +1000
| Lines: 4
| MIME-Version: 1.0
| Content-Type: text/plain;
| format=flowed;
| charset="iso-8859-1";
| reply-type=original
| Content-Transfer-Encoding: 8bit
| X-Priority: 3
| X-MSMail-Priority: Normal
| Importance: Normal
| X-Newsreader: Microsoft Windows Live Mail 12.0.1606
| X-MimeOLE: Produced By Microsoft MimeOLE V12.0.1606
| Message-ID: <#[email protected]>
| Newsgroups: microsoft.public.dotnet.framework.aspnet
| NNTP-Posting-Host: 203-214-145-181.perm.iinet.net.au 203.214.145.181
| Path: TK2MSFTNGHUB02.phx.gbl!TK2MSFTNGP01.phx.gbl!TK2MSFTNGP05.phx.gbl
| Xref: TK2MSFTNGHUB02.phx.gbl
microsoft.public.dotnet.framework.aspnet:75681
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
|
| Thanks- the code works for displaying a "person".
|
| However, the other half of the problem, is how I display the fullname in
a
| related table. Let's say the person has an Entry into a competition, so
for
| an Entry there is a PersonId, a CompId, and a TicketNumber field. When I
| display a list of entries for a competition, I need to display the
fullname,
| as a combination of both FirstName and LastName.
|
| I can't see an obvious way to modify the ForeignKey.ascx class to lookup
two
| fields from the parent entity- it only gets the "GetDisplayString()"-
which
| is returned based on the [DisplayColumn()] attribute of the Person class-
| and I can only specify individual fields in DisplayColumn().
|
| How can I show the FullName for each related parent person in a list?
|
| Thanks,
| +Mark
|
| | > Hi Mark,
| >
| > If I'm correct you're using my second suggestion. To do this please try
| > following steps:
| >
| > 1. Add a new Web UserControl called FullNameControl.ascx in the
| > FieldTemplates folder. Here's the code:
| > ascx:
| > <%@ Control Language="C#" AutoEventWireup="true"
| > CodeBehind="FullNameControl.ascx.cs"
| > Inherits="DynamicAspNetTest.DynamicData.FieldTemplates.FullNameControl"
%>
| > <asp:Literal runat="server" ID="Literal1" Text='<%#
| > Eval("FirstName").ToString() + "," + Eval("LastName").ToString() %>' />
| >
| > ascx.cs:
| >
| > using System;
| > using System.Collections.Generic;
| > using System.Linq;
| > using System.Web;
| > using System.Web.UI;
| > using System.Web.UI.WebControls;
| >
| > namespace DynamicAspNetTest.DynamicData.FieldTemplates
| > {
| > public partial class NameControl :
| > System.Web.DynamicData.FieldTemplateUserControl
| > {
| > public override Control DataControl
| > {
| > get
| > {
| > return Literal1;
| > }
| > }
| > }
| > }
| >
| > 2. Edit the partial class:
| > [MetadataType(typeof(PersonMetadata))]
| > public partial class Person
| > {
| >
| > }
| >
| > public class PersonMetadata
| > {
| > //Show FullName in the FirstName column
| > [UIHint("FullNameControl")]
| > [DisplayName("FullName")]
| > public string FirstName { get; set; }
| >
| > //Hide LastName
| > [ScaffoldColumn(false)]
| > public string LastName { get; set; }
| >
| >
| > }
| >
| > Please note, the "FullName" only appears at [DisplayName("FullName")].
We
| > don't have to add a new property in the PersonMetadata calss. The idea
is
| > to change the DisplayName of the FistName field and use a custom UI
| > (FullNameControl.ascx) to let it show the "FullName".
| >
| > Please have a try and let me know if my code works.
| >
| > Regards,
| > Allen Chen
| > Microsoft Online Support
| >
| > --------------------
| > | From: "markla" <[email protected]>
| > | References: <[email protected]>
| > <#[email protected]>
| > | Subject: Re: DynamicData pages and additional fields on an EDM model
| > | Date: Fri, 5 Sep 2008 05:48:32 -0400
| > | Lines: 1
| > | MIME-Version: 1.0
| > | Content-Type: text/plain;
| > | format=flowed;
| > | charset="iso-8859-1";
| > | reply-type=response
| > | Content-Transfer-Encoding: 8bit
| > | X-Priority: 3
| > | X-MSMail-Priority: Normal
| > | Importance: Normal
| > | X-Newsreader: Microsoft Windows Live Mail 12.0.1606
| > | X-MimeOLE: Produced By Microsoft MimeOLE V12.0.1606
| > | Message-ID: <[email protected]>
| > | Newsgroups:
| >
microsoft.public.dotnet.framework.adonet,microsoft.public.dotnet.framework.a
| > spnet
| > | NNTP-Posting-Host: 12-50-98-46.att-inc.com 12.50.98.46
| > | Path: TK2MSFTNGHUB02.phx.gbl!TK2MSFTNGP01.phx.gbl!TK2MSFTNGP04.phx.gbl
| > | Xref: TK2MSFTNGHUB02.phx.gbl
| > microsoft.public.dotnet.framework.aspnet:75318
| > microsoft.public.dotnet.framework.adonet:11114
| > | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
| > |
| > | Thanks- unfortunately I still get the same error: "The display column
| > | 'FullName' specified for the table 'People' does not exist."
| > |
| > | I'm using c#. Below is the code, for information. I've tried the
| > | ScaffoldColumn attribute on the property, and in the metadata class,
| > neither
| > | make any difference.
| > |
| > | Suggestions, anyone?
| > |
| > | --->
| > | [MetadataType(typeof(PersonMetadata))]
| > | [ScaffoldTable(true)]
| > | [DisplayColumn("FullName")]
| > | [DisplayName("Person")]
| > | public partial class Person
| > | {
| > | public string FullName
| > | {
| > | get
| > | {
| > | return this.LastName + ", " + this.FirstName;
| > | }
| > | }
| > | }
| > | public class PersonMetadata
| > | {
| > | [ScaffoldColumn(false)]
| > | public string PersonId;
| > |
| > | [ScaffoldColumn(true)]
| > | public string FullName;
| > | }
| > | --->
| > |
| > | | > | > - Create a partial Class of your entity
| > | > - Add a Public ReadOnly Property for the compute column
| > | > - Add atrtribute ScaffoldColumnAttribute(True) to the Property
| > | >
| > | > Atte. Elmer Carías
| > | > DCE 4
| > | > El Salvador , Central America
| > | >
| > | >
| > | >
| > | > "markla" <[email protected]> escribió en el mensaje
| > | > | > | >> Hi,
| > | >>
| > | >> I have an EDM model, which I'm rendering using DynamicData pages.
| > | >>
| > | >> I need to add a derived/calculated field.
| > | >>
| > | >> For example, in a "Person" entity, I have LastName and FirstName. I
| > need
| > | >> to add a derived field FullName (being LastName + ", " + FirstName)
| > | >>
| > | >> I have tried adding the FullName field to Person's EDM partial
class,
| > and
| > | >> set the column to be scaffolded, however I can't get FullName to
| > display.
| > | >>
| > | >> Any tips on how to get derived fields to show in DynamicData pages?
| > | >>
| > | >> Thanks,
| > | >> +Mark
| > | >
| > | >
| > |
| >
|
 
Hi Mark,
Can my code work?

Regards,
Allen Chen
Microsoft Online Support
--------------------
| From: "markla" <[email protected]>
| References: <[email protected]>
<#[email protected]>
<[email protected]>
<[email protected]>
| Subject: Re: DynamicData pages and additional fields on an EDM model
| Date: Wed, 10 Sep 2008 11:31:10 +1000
| Lines: 4
| MIME-Version: 1.0
| Content-Type: text/plain;
| format=flowed;
| charset="iso-8859-1";
| reply-type=original
| Content-Transfer-Encoding: 8bit
| X-Priority: 3
| X-MSMail-Priority: Normal
| Importance: Normal
| X-Newsreader: Microsoft Windows Live Mail 12.0.1606
| X-MimeOLE: Produced By Microsoft MimeOLE V12.0.1606
| Message-ID: <#[email protected]>
| Newsgroups: microsoft.public.dotnet.framework.aspnet
| NNTP-Posting-Host: 203-214-145-181.perm.iinet.net.au 203.214.145.181
| Path: TK2MSFTNGHUB02.phx.gbl!TK2MSFTNGP01.phx.gbl!TK2MSFTNGP05.phx.gbl
| Xref: TK2MSFTNGHUB02.phx.gbl
microsoft.public.dotnet.framework.aspnet:75681
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
|
| Thanks- the code works for displaying a "person".
|
| However, the other half of the problem, is how I display the fullname in
a
| related table. Let's say the person has an Entry into a competition, so
for
| an Entry there is a PersonId, a CompId, and a TicketNumber field. When I
| display a list of entries for a competition, I need to display the
fullname,
| as a combination of both FirstName and LastName.
|
| I can't see an obvious way to modify the ForeignKey.ascx class to lookup
two
| fields from the parent entity- it only gets the "GetDisplayString()"-
which
| is returned based on the [DisplayColumn()] attribute of the Person class-
| and I can only specify individual fields in DisplayColumn().
|
| How can I show the FullName for each related parent person in a list?
|
| Thanks,
| +Mark
|
| | > Hi Mark,
| >
| > If I'm correct you're using my second suggestion. To do this please try
| > following steps:
| >
| > 1. Add a new Web UserControl called FullNameControl.ascx in the
| > FieldTemplates folder. Here's the code:
| > ascx:
| > <%@ Control Language="C#" AutoEventWireup="true"
| > CodeBehind="FullNameControl.ascx.cs"
| > Inherits="DynamicAspNetTest.DynamicData.FieldTemplates.FullNameControl"
%>
| > <asp:Literal runat="server" ID="Literal1" Text='<%#
| > Eval("FirstName").ToString() + "," + Eval("LastName").ToString() %>' />
| >
| > ascx.cs:
| >
| > using System;
| > using System.Collections.Generic;
| > using System.Linq;
| > using System.Web;
| > using System.Web.UI;
| > using System.Web.UI.WebControls;
| >
| > namespace DynamicAspNetTest.DynamicData.FieldTemplates
| > {
| > public partial class NameControl :
| > System.Web.DynamicData.FieldTemplateUserControl
| > {
| > public override Control DataControl
| > {
| > get
| > {
| > return Literal1;
| > }
| > }
| > }
| > }
| >
| > 2. Edit the partial class:
| > [MetadataType(typeof(PersonMetadata))]
| > public partial class Person
| > {
| >
| > }
| >
| > public class PersonMetadata
| > {
| > //Show FullName in the FirstName column
| > [UIHint("FullNameControl")]
| > [DisplayName("FullName")]
| > public string FirstName { get; set; }
| >
| > //Hide LastName
| > [ScaffoldColumn(false)]
| > public string LastName { get; set; }
| >
| >
| > }
| >
| > Please note, the "FullName" only appears at [DisplayName("FullName")].
We
| > don't have to add a new property in the PersonMetadata calss. The idea
is
| > to change the DisplayName of the FistName field and use a custom UI
| > (FullNameControl.ascx) to let it show the "FullName".
| >
| > Please have a try and let me know if my code works.
| >
| > Regards,
| > Allen Chen
| > Microsoft Online Support
| >
| > --------------------
| > | From: "markla" <[email protected]>
| > | References: <[email protected]>
| > <#[email protected]>
| > | Subject: Re: DynamicData pages and additional fields on an EDM model
| > | Date: Fri, 5 Sep 2008 05:48:32 -0400
| > | Lines: 1
| > | MIME-Version: 1.0
| > | Content-Type: text/plain;
| > | format=flowed;
| > | charset="iso-8859-1";
| > | reply-type=response
| > | Content-Transfer-Encoding: 8bit
| > | X-Priority: 3
| > | X-MSMail-Priority: Normal
| > | Importance: Normal
| > | X-Newsreader: Microsoft Windows Live Mail 12.0.1606
| > | X-MimeOLE: Produced By Microsoft MimeOLE V12.0.1606
| > | Message-ID: <[email protected]>
| > | Newsgroups:
| >
microsoft.public.dotnet.framework.adonet,microsoft.public.dotnet.framework.a
| > spnet
| > | NNTP-Posting-Host: 12-50-98-46.att-inc.com 12.50.98.46
| > | Path: TK2MSFTNGHUB02.phx.gbl!TK2MSFTNGP01.phx.gbl!TK2MSFTNGP04.phx.gbl
| > | Xref: TK2MSFTNGHUB02.phx.gbl
| > microsoft.public.dotnet.framework.aspnet:75318
| > microsoft.public.dotnet.framework.adonet:11114
| > | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
| > |
| > | Thanks- unfortunately I still get the same error: "The display column
| > | 'FullName' specified for the table 'People' does not exist."
| > |
| > | I'm using c#. Below is the code, for information. I've tried the
| > | ScaffoldColumn attribute on the property, and in the metadata class,
| > neither
| > | make any difference.
| > |
| > | Suggestions, anyone?
| > |
| > | --->
| > | [MetadataType(typeof(PersonMetadata))]
| > | [ScaffoldTable(true)]
| > | [DisplayColumn("FullName")]
| > | [DisplayName("Person")]
| > | public partial class Person
| > | {
| > | public string FullName
| > | {
| > | get
| > | {
| > | return this.LastName + ", " + this.FirstName;
| > | }
| > | }
| > | }
| > | public class PersonMetadata
| > | {
| > | [ScaffoldColumn(false)]
| > | public string PersonId;
| > |
| > | [ScaffoldColumn(true)]
| > | public string FullName;
| > | }
| > | --->
| > |
| > | | > | > - Create a partial Class of your entity
| > | > - Add a Public ReadOnly Property for the compute column
| > | > - Add atrtribute ScaffoldColumnAttribute(True) to the Property
| > | >
| > | > Atte. Elmer Carías
| > | > DCE 4
| > | > El Salvador , Central America
| > | >
| > | >
| > | >
| > | > "markla" <[email protected]> escribió en el mensaje
| > | > | > | >> Hi,
| > | >>
| > | >> I have an EDM model, which I'm rendering using DynamicData pages.
| > | >>
| > | >> I need to add a derived/calculated field.
| > | >>
| > | >> For example, in a "Person" entity, I have LastName and FirstName. I
| > need
| > | >> to add a derived field FullName (being LastName + ", " + FirstName)
| > | >>
| > | >> I have tried adding the FullName field to Person's EDM partial
class,
| > and
| > | >> set the column to be scaffolded, however I can't get FullName to
| > display.
| > | >>
| > | >> Any tips on how to get derived fields to show in DynamicData pages?
| > | >>
| > | >> Thanks,
| > | >> +Mark
| > | >
| > | >
| > |
| >
|
 
Thanks Allen- it works as expected.

Much appreciated.

+Mark


Allen Chen said:
Hi Mark,
We can use a similar approach to achieve this for the Competition table.

1. Firstly add a Web User Control MyForeignKey.ascx in the FieldTemplates
folder:

ascx:
<%@ Control Language="C#" AutoEventWireup="true"
CodeBehind="MyForeignKey.ascx.cs"
Inherits="DynamicAspNetTest.DynamicData.FieldTemplates.MyForeignKey" %>
<asp:Literal runat="server" ID="Literal1" Text="<%# GetDisplayString()
%>"/>

ascx.cs:
public partial class MyForeignKey :
System.Web.DynamicData.FieldTemplateUserControl
{
public override Control DataControl
{
get
{

return Literal1;
}
}
protected string GetDisplayString()
{
Person p=(Person)FieldValue;
string fullname= p.FirstName + "," + p.LastName;
return fullname;
}
}

2. Edit the partial class:
[MetadataType(typeof(CompetitionHeaderMetadata))]
public partial class Competition
{

}
public class CompetitionHeaderMetadata
{

[UIHint("MyForeignKey")]
public Customer Customer { get; set; }

}

Please try it and let me know if it works.

Thanks,
Allen Chen
Microsoft Online Support

--------------------
| From: "markla" <[email protected]>
| References: <[email protected]>
<#[email protected]>
<[email protected]>
<[email protected]>
| Subject: Re: DynamicData pages and additional fields on an EDM model
| Date: Wed, 10 Sep 2008 11:31:10 +1000
| Lines: 4
| MIME-Version: 1.0
| Content-Type: text/plain;
| format=flowed;
| charset="iso-8859-1";
| reply-type=original
| Content-Transfer-Encoding: 8bit
| X-Priority: 3
| X-MSMail-Priority: Normal
| Importance: Normal
| X-Newsreader: Microsoft Windows Live Mail 12.0.1606
| X-MimeOLE: Produced By Microsoft MimeOLE V12.0.1606
| Message-ID: <#[email protected]>
| Newsgroups: microsoft.public.dotnet.framework.aspnet
| NNTP-Posting-Host: 203-214-145-181.perm.iinet.net.au 203.214.145.181
| Path: TK2MSFTNGHUB02.phx.gbl!TK2MSFTNGP01.phx.gbl!TK2MSFTNGP05.phx.gbl
| Xref: TK2MSFTNGHUB02.phx.gbl
microsoft.public.dotnet.framework.aspnet:75681
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
|
| Thanks- the code works for displaying a "person".
|
| However, the other half of the problem, is how I display the fullname in
a
| related table. Let's say the person has an Entry into a competition, so
for
| an Entry there is a PersonId, a CompId, and a TicketNumber field. When I
| display a list of entries for a competition, I need to display the
fullname,
| as a combination of both FirstName and LastName.
|
| I can't see an obvious way to modify the ForeignKey.ascx class to lookup
two
| fields from the parent entity- it only gets the "GetDisplayString()"-
which
| is returned based on the [DisplayColumn()] attribute of the Person
class-
| and I can only specify individual fields in DisplayColumn().
|
| How can I show the FullName for each related parent person in a list?
|
| Thanks,
| +Mark
|
| | > Hi Mark,
| >
| > If I'm correct you're using my second suggestion. To do this please
try
| > following steps:
| >
| > 1. Add a new Web UserControl called FullNameControl.ascx in the
| > FieldTemplates folder. Here's the code:
| > ascx:
| > <%@ Control Language="C#" AutoEventWireup="true"
| > CodeBehind="FullNameControl.ascx.cs"
| >
Inherits="DynamicAspNetTest.DynamicData.FieldTemplates.FullNameControl"
%>
| > <asp:Literal runat="server" ID="Literal1" Text='<%#
| > Eval("FirstName").ToString() + "," + Eval("LastName").ToString() %>'
/>
| >
| > ascx.cs:
| >
| > using System;
| > using System.Collections.Generic;
| > using System.Linq;
| > using System.Web;
| > using System.Web.UI;
| > using System.Web.UI.WebControls;
| >
| > namespace DynamicAspNetTest.DynamicData.FieldTemplates
| > {
| > public partial class NameControl :
| > System.Web.DynamicData.FieldTemplateUserControl
| > {
| > public override Control DataControl
| > {
| > get
| > {
| > return Literal1;
| > }
| > }
| > }
| > }
| >
| > 2. Edit the partial class:
| > [MetadataType(typeof(PersonMetadata))]
| > public partial class Person
| > {
| >
| > }
| >
| > public class PersonMetadata
| > {
| > //Show FullName in the FirstName column
| > [UIHint("FullNameControl")]
| > [DisplayName("FullName")]
| > public string FirstName { get; set; }
| >
| > //Hide LastName
| > [ScaffoldColumn(false)]
| > public string LastName { get; set; }
| >
| >
| > }
| >
| > Please note, the "FullName" only appears at [DisplayName("FullName")].
We
| > don't have to add a new property in the PersonMetadata calss. The
idea
is
| > to change the DisplayName of the FistName field and use a custom UI
| > (FullNameControl.ascx) to let it show the "FullName".
| >
| > Please have a try and let me know if my code works.
| >
| > Regards,
| > Allen Chen
| > Microsoft Online Support
| >
| > --------------------
| > | From: "markla" <[email protected]>
| > | References: <[email protected]>
| > <#[email protected]>
| > | Subject: Re: DynamicData pages and additional fields on an EDM model
| > | Date: Fri, 5 Sep 2008 05:48:32 -0400
| > | Lines: 1
| > | MIME-Version: 1.0
| > | Content-Type: text/plain;
| > | format=flowed;
| > | charset="iso-8859-1";
| > | reply-type=response
| > | Content-Transfer-Encoding: 8bit
| > | X-Priority: 3
| > | X-MSMail-Priority: Normal
| > | Importance: Normal
| > | X-Newsreader: Microsoft Windows Live Mail 12.0.1606
| > | X-MimeOLE: Produced By Microsoft MimeOLE V12.0.1606
| > | Message-ID: <[email protected]>
| > | Newsgroups:
| >
microsoft.public.dotnet.framework.adonet,microsoft.public.dotnet.framework.a
| > spnet
| > | NNTP-Posting-Host: 12-50-98-46.att-inc.com 12.50.98.46
| > | Path:
TK2MSFTNGHUB02.phx.gbl!TK2MSFTNGP01.phx.gbl!TK2MSFTNGP04.phx.gbl
| > | Xref: TK2MSFTNGHUB02.phx.gbl
| > microsoft.public.dotnet.framework.aspnet:75318
| > microsoft.public.dotnet.framework.adonet:11114
| > | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
| > |
| > | Thanks- unfortunately I still get the same error: "The display
column
| > | 'FullName' specified for the table 'People' does not exist."
| > |
| > | I'm using c#. Below is the code, for information. I've tried the
| > | ScaffoldColumn attribute on the property, and in the metadata class,
| > neither
| > | make any difference.
| > |
| > | Suggestions, anyone?
| > |
| > | --->
| > | [MetadataType(typeof(PersonMetadata))]
| > | [ScaffoldTable(true)]
| > | [DisplayColumn("FullName")]
| > | [DisplayName("Person")]
| > | public partial class Person
| > | {
| > | public string FullName
| > | {
| > | get
| > | {
| > | return this.LastName + ", " + this.FirstName;
| > | }
| > | }
| > | }
| > | public class PersonMetadata
| > | {
| > | [ScaffoldColumn(false)]
| > | public string PersonId;
| > |
| > | [ScaffoldColumn(true)]
| > | public string FullName;
| > | }
| > | --->
| > |
| > | | > | > - Create a partial Class of your entity
| > | > - Add a Public ReadOnly Property for the compute column
| > | > - Add atrtribute ScaffoldColumnAttribute(True) to the Property
| > | >
| > | > Atte. Elmer Carías
| > | > DCE 4
| > | > El Salvador , Central America
| > | >
| > | >
| > | >
| > | > "markla" <[email protected]> escribió en el mensaje
| > | > | > | >> Hi,
| > | >>
| > | >> I have an EDM model, which I'm rendering using DynamicData pages.
| > | >>
| > | >> I need to add a derived/calculated field.
| > | >>
| > | >> For example, in a "Person" entity, I have LastName and FirstName.
I
| > need
| > | >> to add a derived field FullName (being LastName + ", " +
FirstName)
| > | >>
| > | >> I have tried adding the FullName field to Person's EDM partial
class,
| > and
| > | >> set the column to be scaffolded, however I can't get FullName to
| > display.
| > | >>
| > | >> Any tips on how to get derived fields to show in DynamicData
pages?
| > | >>
| > | >> Thanks,
| > | >> +Mark
| > | >
| > | >
| > |
| >
|
 
I am trying something similar, I have a many-to-many table called ActivityUser in which I have a foreign key to the User table. I'm trying in the ActivityUser/ListDetails.aspx to show the 'FirstName,LastName' of a User inside a column.
I tried the approach you have suggested, and if I understood well created an ActivityUser.cs class that extends the data model class; inside this class I put the following code:
[MetadataType(typeof(ActivityMetaData))]
public partial class ActivityUser
{
}

public class ActivityMetaData
{
[UIHint("UserForeignKey")]
public User usr { get; set; }
}

with UserForeignKey.ascx being my custom web user control, but whenIi compile the Global.asax throughs the following error:

'The associated metadata type for type 'Qubiz.OfficeManager.DataModel.ActivityUser' contains the following unknown properties or fields: usr. Please make sure that the names of these members match the names of the properties on the main type.'

What am I doing wrong?



v-alche wrote:

Hi Mark,We can use a similar approach to achieve this for the Competition
10-Sep-08

Hi Mark
We can use a similar approach to achieve this for the Competition table.

1. Firstly add a Web User Control MyForeignKey.ascx in the FieldTemplates
folder

ascx
<%@ Control Language="C#" AutoEventWireup="true"
CodeBehind="MyForeignKey.ascx.cs"
Inherits="DynamicAspNetTest.DynamicData.FieldTemplates.MyForeignKey" %
<asp:Literal runat="server" ID="Literal1" Text="<%# GetDisplayString() %>"/

ascx.cs
public partial class MyForeignKey :
System.Web.DynamicData.FieldTemplateUserContro

public override Control DataContro

ge


return Literal1


protected string GetDisplayString(
{
Person p=(Person)FieldValue
string fullname= p.FirstName + "," + p.LastName
return fullname



2. Edit the partial class
[MetadataType(typeof(CompetitionHeaderMetadata))
public partial class Competitio



public class CompetitionHeaderMetadat


[UIHint("MyForeignKey")
public Customer Customer { get; set;



Please try it and let me know if it works

Thanks
Allen Che
Microsoft Online Suppor

-------------------
<#[email protected]>
<[email protected]>
<[email protected]
microsoft.public.dotnet.framework.aspnet:7568
a
for
fullname,
two
which
%
W
i
microsoft.public.dotnet.framework.adonet,microsoft.public.dotnet.framework.
class,

Previous Posts In This Thread:

DynamicData pages and additional fields on an EDM model
Hi

I have an EDM model, which I'm rendering using DynamicData pages

I need to add a derived/calculated field

For example, in a "Person" entity, I have LastName and FirstName. I need to
add a derived field FullName (being LastName + ", " + FirstName

I have tried adding the FullName field to Person's EDM partial class, and
set the column to be scaffolded, however I can't get FullName to display

Any tips on how to get derived fields to show in DynamicData pages

Thanks
+Mark

- Create a partial Class of your entity- Add a Public ReadOnly Property for
- Create a partial Class of your entit
- Add a Public ReadOnly Property for the compute colum
- Add atrtribute ScaffoldColumnAttribute(True) to the Propert

Atte. Elmer Car?a
DCE
El Salvador , Central Americ


"markla" <[email protected]> escribi? en el mensaje

Hi Mark,Due to current limitation of Entity Data Model we cannot achieve this
Hi Mark

Due to current limitation of Entity Data Model we cannot achieve this by
adding a scaffold property in the partial class.

I have two suggestions for you that can work it around

1. You can customize the page template. Please refer to this video:
http://www.asp.net/learn/3.5-sp1/video-293.aspx

You can set AutoGenerateColumns to true and add an extra column. Something
like this:
<asp:GridView AutoGenerateColumns="True" ID="GridView1" runat="server"
DataSourceID="GridDataSource"
AllowPaging="True" AllowSorting="True" CssClass="gridview">
<Columns>
<asp:TemplateField>
<HeaderTemplate>
FullName
</HeaderTemplate>
<ItemTemplate>
<%#Eval("FirstName").ToString() + "," +
Eval("LastName").ToString() %>
</ItemTemplate></asp:TemplateField>
<asp:TemplateField>

2. You can hide the LastName field and use a custom field template for the
FirstName field. To do this, Add a FullNameControl in the FieldTemplates
folder:

<%@ Control Language="C#" AutoEventWireup="true"
CodeBehind="FullNameControl.ascx.cs"
Inherits="DynamicAspNetTest.DynamicData.FieldTemplates.FullNameControl" %>
<asp:Literal runat="server" ID="Literal1" Text='<%#
Eval("FirstName").ToString() + "," + Eval("LastName").ToString() %>' />

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace DynamicAspNetTest.DynamicData.FieldTemplates
{
public partial class NameControl :
System.Web.DynamicData.FieldTemplateUserControl
{
public override Control DataControl
{
get
{
return Literal1;
}
}
}
}

Then edit your partial class:

[MetadataType(typeof(PersonMetadata))]
public partial class Person
{

}

public class PersonMetadata
{
//Show FullName in the FirstName column
[UIHint("FullNameControl")]
[DisplayName("FullName")]
public string FirstName { get; set; }

//Hide LastName
[ScaffoldColumn(false)]
public string LastName { get; set; }


}

Please have a try and feel free to ask if you have further questions.

Regards,
Allen Chen
Microsoft Online Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

--------------------
microsoft.public.dotnet.framework.adonet,microsoft.public.dotnet.framework.a
spnet
microsoft.public.dotnet.framework.aspnet:75165
microsoft.public.dotnet.framework.adonet:11090
to

Re: DynamicData pages and additional fields on an EDM model
Thanks- unfortunately I still get the same error: "The display column
'FullName' specified for the table 'People' does not exist."

I'm using c#. Below is the code, for information. I've tried the
ScaffoldColumn attribute on the property, and in the metadata class, neither
make any difference.

Suggestions, anyone?

--->
[MetadataType(typeof(PersonMetadata))]
[ScaffoldTable(true)]
[DisplayColumn("FullName")]
[DisplayName("Person")]
public partial class Person
{
public string FullName
{
get
{
return this.LastName + ", " + this.FirstName;
}
}
}
public class PersonMetadata
{
[ScaffoldColumn(false)]
public string PersonId;

[ScaffoldColumn(true)]
public string FullName;
}
--->


Hi Mark,If I'm correct you're using my second suggestion.
Hi Mark,

If I'm correct you're using my second suggestion. To do this please try
following steps:

1. Add a new Web UserControl called FullNameControl.ascx in the
FieldTemplates folder. Here's the code:
ascx:
<%@ Control Language="C#" AutoEventWireup="true"
CodeBehind="FullNameControl.ascx.cs"
Inherits="DynamicAspNetTest.DynamicData.FieldTemplates.FullNameControl" %>
<asp:Literal runat="server" ID="Literal1" Text='<%#
Eval("FirstName").ToString() + "," + Eval("LastName").ToString() %>' />

ascx.cs:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace DynamicAspNetTest.DynamicData.FieldTemplates
{
public partial class NameControl :
System.Web.DynamicData.FieldTemplateUserControl
{
public override Control DataControl
{
get
{
return Literal1;
}
}
}
}

2. Edit the partial class:
[MetadataType(typeof(PersonMetadata))]
public partial class Person
{

}

public class PersonMetadata
{
//Show FullName in the FirstName column
[UIHint("FullNameControl")]
[DisplayName("FullName")]
public string FirstName { get; set; }

//Hide LastName
[ScaffoldColumn(false)]
public string LastName { get; set; }


}

Please note, the "FullName" only appears at [DisplayName("FullName")]. We
don't have to add a new property in the PersonMetadata calss. The idea is
to change the DisplayName of the FistName field and use a custom UI
(FullNameControl.ascx) to let it show the "FullName".

Please have a try and let me know if my code works.

Regards,
Allen Chen
Microsoft Online Support

--------------------
<#[email protected]>
microsoft.public.dotnet.framework.adonet,microsoft.public.dotnet.framework.a
spnet
microsoft.public.dotnet.framework.aspnet:75318
microsoft.public.dotnet.framework.adonet:11114
neither
need
and
display.

Hi Mark,Have you tried my suggestion? Can my code work?
Hi Mark,

Have you tried my suggestion? Can my code work?

Regards,
Allen Chen
Microsoft Online Community Support
--------------------
<#[email protected]>
microsoft.public.dotnet.framework.adonet,microsoft.public.dotnet.framework.a
spnet
microsoft.public.dotnet.framework.aspnet:75318
microsoft.public.dotnet.framework.adonet:11114
neither
need
and
display.

Thanks- the code works for displaying a "person".
Thanks- the code works for displaying a "person".

However, the other half of the problem, is how I display the fullname in a
related table. Let's say the person has an Entry into a competition, so for
an Entry there is a PersonId, a CompId, and a TicketNumber field. When I
display a list of entries for a competition, I need to display the fullname,
as a combination of both FirstName and LastName.

I can't see an obvious way to modify the ForeignKey.ascx class to lookup two
fields from the parent entity- it only gets the "GetDisplayString()"- which
is returned based on the [DisplayColumn()] attribute of the Person class-
and I can only specify individual fields in DisplayColumn().

How can I show the FullName for each related parent person in a list?

Thanks,
+Mark


Hi Mark,We can use a similar approach to achieve this for the Competition
Hi Mark,
We can use a similar approach to achieve this for the Competition table.

1. Firstly add a Web User Control MyForeignKey.ascx in the FieldTemplates
folder:

ascx:
<%@ Control Language="C#" AutoEventWireup="true"
CodeBehind="MyForeignKey.ascx.cs"
Inherits="DynamicAspNetTest.DynamicData.FieldTemplates.MyForeignKey" %>
<asp:Literal runat="server" ID="Literal1" Text="<%# GetDisplayString() %>"/>

ascx.cs:
public partial class MyForeignKey :
System.Web.DynamicData.FieldTemplateUserControl
{
public override Control DataControl
{
get
{

return Literal1;
}
}
protected string GetDisplayString()
{
Person p=(Person)FieldValue;
string fullname= p.FirstName + "," + p.LastName;
return fullname;
}
}

2. Edit the partial class:
[MetadataType(typeof(CompetitionHeaderMetadata))]
public partial class Competition
{

}
public class CompetitionHeaderMetadata
{

[UIHint("MyForeignKey")]
public Customer Customer { get; set; }

}

Please try it and let me know if it works.

Thanks,
Allen Chen
Microsoft Online Support

--------------------
<#[email protected]>
<[email protected]>
<[email protected]>
microsoft.public.dotnet.framework.aspnet:75681
a
for
fullname,
two
which
%>
We
is
microsoft.public.dotnet.framework.adonet,microsoft.public.dotnet.framework.a
class,

Hi Mark,Can my code work?
Hi Mark,
Can my code work?

Regards,
Allen Chen
Microsoft Online Support
--------------------
<#[email protected]>
<[email protected]>
<[email protected]>
microsoft.public.dotnet.framework.aspnet:75681
a
for
fullname,
two
which
%>
We
is
microsoft.public.dotnet.framework.adonet,microsoft.public.dotnet.framework.a
class,

Thanks Allen- it works as expected.Much appreciated.
Thanks Allen- it works as expected.

Much appreciated.

+Mark


Submitted via EggHeadCafe - Software Developer Portal of Choice
Distributed Data Grids - Share Objects Between Windows Service and ASP.NET
http://www.eggheadcafe.com/tutorial...b7a-1bb00e33db07/distributed-data-grids-.aspx
 
Back
Top