Question

I'm searching info about configuring own MetaData in asp.NET Dynamic Site.

For example. I have a table in MS Sql Server with structure shown below:

CREATE TABLE [dbo].[someTable](
    [id] [int] NOT NULL,
    [pname] [nvarchar](20) NULL,
    [FullName] [nvarchar](50) NULL,
    [age] [int] NULL)

and I there are 2 Ms Sql tables (I've created), sysTables and sysColumns.

sysTables:

ID sysTableName TableName TableDescription

1 | someTable |Persons |All Data about Persons in system

sysColumns:

ID TableName sysColumnName ColumnName ColumnDesc ColumnType MUnit

1 |someTable | sometable_pname| Name | Persona Name(ex. John)| nvarchar(20) | null
2 |someTable | sometable_Fullname| Full Name | Persona Name(ex. John Black)| nvarchar(50) | null
3 |someTable | sometable_age| age | Person age| int | null

I want that, in Details/Edit/Insert/List/ListDetails pages use as MetaData sysColumns and sysTableData. Because, for ex. in DetailsPage fullName, it is not beatiful as Full Name .

someIdea, is it possible?

thanks

Updated:: In List Page to display data from sysTables (metaData table) I've modified <h2 class="DDSubHeader"><%= tableName%></h2>.

public string tableName;
protected void Page_Init(object sender, EventArgs e)
{

            table = DynamicDataRouteHandler.GetRequestMetaTable(Context);
            //added by me
            uqsikDataContext sd=new uqsikDataContext();
            tableName = sd.sysTables.Where(n => n.sysTableName == table.DisplayName).FirstOrDefault().TableName;
            //end

            GridView1.SetMetaTable(table, table.GetColumnValuesFromRoute(Context));
            GridDataSource.EntityTypeName = table.EntityType.AssemblyQualifiedName;
            if (table.EntityType != table.RootEntityType)
            {
                GridQueryExtender.Expressions.Add(new OfTypeExpression(table.EntityType));
            }
 }

so, what about sysColums? How can I get Data from my sysColumns table?

Was it helpful?

Solution 2

I've found useful article, than can be used for solution my problem

OTHER TIPS

In a word, yes, it is possible. However, I do not believe this is a good idea. What you are really talking about is storing presentation data in your database, when really the best place to put this is in your aspx pages themselves. That being said, if you want to store data dictionary type information in your DB, I'd recommend making use of the built in sys.tables, sys.columns, and sys.types views that are built into MS SQL Server, and adding a table called ObjectDescriptions to store the display name and type.

create table ObjectDescriptions (
   object_id int not null,
   column_id null, --leave this column null if the record describes the table itself
   ObjectDisplayName nvarchar(20),
   ObjectDescription nvarchar(200)
 );

Then, you could create a view based on object ID to retrieve the meta data of your table, and either directly bind or dynamically populate your asp.net FormView.

create view TableData as     
select 
     t.name as table_name
    ,td.ObjectDisplayName as table_display_name
    ,td.ObjectDescription as table_description
    ,c.name as column_name
    ,cd.ObjectDisplayName as column_display_name
    ,cd.ObjectDescription as column_description
    ,c.column_id
    ,ty.name as [type_name]
    ,c.max_length
    ,c.scale
    ,c.[precision]
from sys.tables t
    left join ObjectDescriptions td on td.object_id = t.object_id
    join sys.columns c on c.object_id = t.object_id
    left join ObjectDescriptions cd on cd.column_id = c.column_id and cd.object_id  = c.object_id
    join sys.types ty on c.user_type_id = ty.user_type_id

EDIT:

You can then leverage this view in your ASP code by writing a class that holds your meta data about a single table, and writing a method in your DAL to retrieve an instance of this class based on object or table name. When you populate your page, the page could retrieve both the record you are looking for, as well as the table's meta-data, and bind that meta data to either grid headers (in list view) or to individual label's accompanying text boxes in single record mode.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top