Get primary key fields

Posts   
 
    
jesterJP
User
Posts: 30
Joined: 21-Nov-2007
# Posted on: 11-Dec-2007 18:11:39   

I am programmatically creating a LLBLGenProDataSource2 and dynamically setting the EntityFactoryTypeName based on a tablename picked from a dropdownlistbox. After creating this datasource, then I bind it to a Gridview. This code works great. Now, I would like to determine what is the primary key fields of the Entity in the datasource. My code is below:


String SPTN = "";
                Array PTN = this.DDLBCodeTables.SelectedValue.Split('_');
                foreach (string nm in PTN)
                {
                    string TableName;
                    string FirstLetter = nm.Substring(0, 1);
                    TableName = FirstLetter.ToUpper() + nm.Substring(1);
                    SPTN = SPTN + TableName;
                }

                string EFTN = "DBASupport.LLBL.DAL.FactoryClasses." + SPTN + "EntityFactory, DBASupport.LLBL.DAL";
                datasource = new LLBLGenProDataSource2();
                datasource.ID = "ODSRuntime";
                datasource.DataContainerType = DataSourceDataContainerType.EntityCollection;
                datasource.AdapterTypeName = "DBASupport.LLBL.DAL.DatabaseSpecific.DataAccessAdapter, DBASupport.LLBL.DALDBSpecific";
                datasource.EntityFactoryTypeName = EFTN;
                PHCodeTable.Controls.Clear();
                GVCodeTable = new GridView();
                GVCodeTable.EnableViewState=true;
                GVCodeTable.AutoGenerateColumns=true;
                GVCodeTable.AutoGenerateSelectButton = true;
                GVCodeTable.DataSource = datasource;
                PHCodeTable.Controls.Add(GVCodeTable);
                GVCodeTable.DataBind();

Any ideas how to get the primary key from the datasource?

Thanks....

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 12-Dec-2007 11:00:45   

Using the entityFactory, you can create an instance of the entity and you can loop through its Fields collection to check for each EntityField's IsPrimaryKey flag.