New Posts New Posts RSS Feed: Getting primary key information for arbitrary Entity type
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Getting primary key information for arbitrary Entity type

 Post Reply Post Reply
Author
vecs View Drop Down
Newbie
Newbie


Joined: 05-Dec-2007
Location: Russian Federation
Posts: 22
Post Options Post Options   Quote vecs Quote  Post ReplyReply Direct Link To This Post Topic: Getting primary key information for arbitrary Entity type
    Posted: 26-Jun-2008 at 12:47am
Thanks to all!

Here is the C# code I finally use:

    public static class IbUtils
    {
        public static List<EntityColumn> GetPKColumns(Type pEntityType)
        {
            List<EntityColumn> pkColumns = new List<EntityColumn>();
            foreach (EntityColumn column in EntityColumn.GetEntityColumns(pEntityType))
            {
                if (column.IsPrimaryKeyColumn)
                    pkColumns.Add(column);
            }
            return pkColumns;
        }
        //...
    }

Usage example:

        List<EntityColumn> pkColumns = IbUtils.GetPKColumns(someEntityType);




Edited by vecs - 26-Jun-2008 at 12:53am
Back to Top
f3rland View Drop Down
Newbie
Newbie
Avatar

Joined: 13-Sep-2007
Location: Canada
Posts: 25
Post Options Post Options   Quote f3rland Quote  Post ReplyReply Direct Link To This Post Posted: 25-Jun-2008 at 11:33am
Generic function to retreive PKColumn list in VB.NET
Adjust it to fit your needs

   Private Function GetPK(Of t As IdeaBlade.Persistence.Entity)() As Collections.Generic.List(Of IdeaBlade.Persistence.EntityColumn)
      Dim oResult As New Collections.Generic.List(Of IdeaBlade.Persistence.EntityColumn)

      For Each ec As IdeaBlade.Persistence.EntityColumn In IdeaBlade.Persistence.EntityColumn.GetEntityColumns(GetType(t))
         If ec.IsPrimaryKeyColumn Then
            oResult.Add(ec)
         End If
      Next

      Return oResult
   End Function

Usage
Dim oList As Collections.Generic.List(Of IdeaBlade.Persistence.EntityColumn)
oList = GetPK(Of Model.Employee)



Edited by f3rland - 26-Jun-2008 at 6:07am
F3
Back to Top
davidklitzke View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 14-Jun-2007
Posts: 715
Post Options Post Options   Quote davidklitzke Quote  Post ReplyReply Direct Link To This Post Posted: 25-Jun-2008 at 11:06am
IdeaBlade does not have such a thing as a Primary Key collection, so this is a good solution.
Back to Top
GeoffAtDatagaard View Drop Down
Newbie
Newbie
Avatar

Joined: 23-Jun-2008
Location: South Australia
Posts: 2
Post Options Post Options   Quote GeoffAtDatagaard Quote  Post ReplyReply Direct Link To This Post Posted: 25-Jun-2008 at 7:45am
Im a newbie too, so I'd appreciate knowing an easier way than this
(Maybe a primary key collection somewhere)
 
foreach (EntityColumn ec in EntityColumn.GetEntityColumns(typeof(Employee))) {
if (ec.IsPrimaryKeyColumn) {
  // This is a primary key column
}
}
 
or
 
For Each ec As EntityColumn In EntityColumn.GetEntityColumns(GetType(Employee))
 If ec.IsPrimaryKeyColumn Then
  ' This is a primary key column
 End If
Next
Back to Top
vecs View Drop Down
Newbie
Newbie


Joined: 05-Dec-2007
Location: Russian Federation
Posts: 22
Post Options Post Options   Quote vecs Quote  Post ReplyReply Direct Link To This Post Posted: 25-Jun-2008 at 6:21am
How to get meta-information about the primary key fields for arbitrary Entity type?
May be in form of PropertyDescriptor collection or something else?

Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down