From: Razvan on
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.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

--------------------
<#XAbGmeDJHA.4800(a)TK2MSFTNGP06.phx.gbl>
<erstSyzDJHA.232(a)TK2MSFTNGP04.phx.gbl>
<ClluteVEJHA.6100(a)TK2MSFTNGHUB02.phx.gbl>
microsoft.public.dotnet.framework.aspnet:75681
a
for
fullname,
two
which
%>
We
is
microsoft.public.dotnet.framework.adonet,microsoft.public.dotnet.framework.a
class,

Previous Posts In This Thread:

On Wednesday, September 03, 2008 2:51 AM
markla wrote:

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

On Wednesday, September 03, 2008 1:21 PM
Elmer Car?as wrote:

- Create a partial Class of your entity- Add a Public ReadOnly Property for
- 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" <markla(a)noemail.noemail> escribi? en el mensaje
news:ucyeNGZDJHA.4732(a)TK2MSFTNGP04.phx.gbl...

On Thursday, September 04, 2008 2:05 AM
v-alche wrote:

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:
msdnmg(a)microsoft.com.

==================================================
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

On Friday, September 05, 2008 5:48 AM
markla wrote:

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;
}
--->

"Elmer Car?as" <elmer_carias(a)hotmail.com> wrote in message
news:#XAbGmeDJHA.4800(a)TK2MSFTNGP06.phx.gbl...

On Sunday, September 07, 2008 10:07 PM
v-alche wrote:

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

--------------------
<#XAbGmeDJHA.4800(a)TK2MSFTNGP06.phx.gbl>
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.

On Tuesday, September 09, 2008 9:28 PM
v-alche wrote:

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
--------------------
<#XAbGmeDJHA.4800(a)TK2MSFTNGP06.phx.gbl>
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.

On Tuesday, September 09, 2008 9:31 PM
markla wrote:

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

"Allen Chen [MSFT]" <v-alchen(a)online.microsoft.com> wrote in message
news:ClluteVEJHA.6100(a)TK2MSFTNGHUB02.phx.gbl...

On Wednesday, September 10, 2008 3:35 AM
v-alche wrote:

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

--------------------
<#XAbGmeDJHA.4800(a)TK2MSFTNGP06.phx.gbl>
<erstSyzDJHA.232(a)TK2MSFTNGP04.phx.gbl>
<ClluteVEJHA.6100(a)TK2MSFTNGHUB02.phx.gbl>
microsoft.public.dotnet.framework.aspnet:75681
a
for
fullname,
two
which
%>
We
is
microsoft.public.dotnet.framework.adonet,microsoft.public.dotnet.framework.a
class,

On Thursday, September 11, 2008 9:24 PM
v-alche wrote:

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

Regards,
Allen Chen
Microsoft Online Support
--------------------
<#XAbGmeDJHA.4800(a)TK2MSFTNGP06.phx.gbl>
<erstSyzDJHA.232(a)TK2MSFTNGP04.phx.gbl>
<ClluteVEJHA.6100(a)TK2MSFTNGHUB02.phx.gbl>
microsoft.public.dotnet.framework.aspnet:75681
a
for
fullname,
two
which
%>
We
is
microsoft.public.dotnet.framework.adonet,microsoft.public.dotnet.framework.a
class,

On Saturday, September 13, 2008 8:51 AM
markla wrote:

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/tutorials/aspnet/953ed61f-e440-4ca5-8b7a-1bb00e33db07/distributed-data-grids-.aspx