Determine if a field is an identity (auto incrementing)

Posts   
 
    
BaileyK83
User
Posts: 29
Joined: 30-Dec-2006
# Posted on: 14-Jul-2007 19:21:43   

Is there anyway to determine if a field is an identity (auto incrementing)

Posts: 254
Joined: 16-Nov-2006
# Posted on: 14-Jul-2007 23:50:06   

1) At the database level e.g. SQL Server you can simply see this as a property of the field in the SQL Server design table form

2) In LLBLGen designer you can see the "Is Identity / Sequence field" in the field properties for the entity.

3) At runtime you can check the EntityField class's IsIdentity property for a field for an entity.

BaileyK83
User
Posts: 29
Joined: 30-Dec-2006
# Posted on: 15-Jul-2007 19:55:16   

I thought I was blind when you said that but I went and double checked. I am trying to do it in code with adapter.

The IsIdentity field is only a member of the entityfield class and not the entityfield2

Is there anyway to find out if an entityfield2 class is an identity field?

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 16-Jul-2007 00:34:05   

Hi BaileyK83, As you are using Adapter TemplateSet you must to use **IFieldPersistenceInfo **class to access the information of a field. You can do that as follow:

  1. Craate a partial class for your DataAccessAdapter class and create a method that retrieves the field information:
using System;
using System.Collections;
using System.Data;
using System.Data.Common;

using SD.LLBLGen.Pro.ORMSupportClasses;
using SD.LLBLGen.Pro.DQE.SqlServer;

// here you should write <yourProjectNamespace>.DatabaseSpecific
namespace Northwind.DatabaseSpecific
{
    public partial class DataAccessAdapter
    {       
        public IFieldPersistenceInfo GetFieldInfo(IEntityField2 field)
        {
            return base.GetFieldPersistenceInfo(field);
        }
    }
}
  1. Use the above method at your BL or GUI code:
using (DataAccessAdapter adapter = new DataAccessAdapter())
{
    // here put GetFieldInfo(<YourEntityName>Fields.<YourEntityField>)
    IFieldPersistenceInfo fieldInfo = adapter.GetFieldInfo(CustomersFields.CustomerId);
    Console.WriteLine("CustomerID IsIdentity = {0}", fieldInfo.IsIdentity);
}

David Elizondo | LLBLGen Support Team
BaileyK83
User
Posts: 29
Joined: 30-Dec-2006
# Posted on: 16-Jul-2007 10:35:55   

I C, since you need to use an adapter then does that call make a trip to the database?

Walaa avatar
Walaa
Support Team
Posts: 14946
Joined: 21-Aug-2005
# Posted on: 16-Jul-2007 11:02:10   

No it doesn't. Persisitence info is accesible to the DataAccessAdapter in the Adapter Template, they are not stored in the entities as in the SelfServicing Template.