This documentation is not maintained. Please refer to doc.castsoftware.com/technologies to find the latest updates.

Summary: This document provides basic information about the extension providing Entity Framework support for C#.

Extension ID

com.castsoftware.entity

What's new?

See Entity Framework 2.1 - Release Notes for more information.

Description

This extension provides support for Entity Framework. The calculation of Automated Function Points for your .NET analyses will be supplemented through the links between objects produced by the base .NET Analyzer and database tables, using Entity Framework CRUD operations.

In what situation should you install this extension?

If your .NET application contains Entity Framework source code and you want to view these object types and their links, then you should install this extension. More specifically the extension will identify:

  • "use" links from C# methods using Entity Framework operations to participating Database tables

Technology support

Entity Framework

Entity Framework is delivered with the .NET Framework. Therefore the following .NET frameworks are supported by this extension:

Version

Supported

3.0 and above(tick)

Entity Framework Core

Entity Framework Core is supported when using AIP Core 8.3.x and above as Entity Framework Core is delivered with .NET Core.

Version

Supported

3.x

       

2.x(tick)
1.x(tick)

Function Point, Quality and Sizing support

This extension provides the following support:

  • Function Points (transactions): a green tick indicates that OMG Function Point counting and Transaction Risk Index are supported
  • Quality and Sizing: a green tick indicates that CAST can measure size and that a minimum set of Quality Rules exist
Function Points
(transactions)
(tick)
Quality and Sizing(tick)

CAST AIP compatibility

This extension is compatible with:

CAST AIP release
Supported
Supported Technology
8.3.x(tick)C#

Supported DBMS servers

This extension is compatible with the following DBMS servers:

DBMSSupported
CSS/PostgreSQL(tick)
Oracle(tick)
Microsoft SQL Server

Prerequisites

(tick)An installation of any compatible release of CAST AIP (see table above)

Download and installation instructions

The extension will not be automatically downloaded and installed in CAST Console. If you need to use it, should manually install the extension using the Application - Extensions interface:

What results can you expect?

Once the analysis/snapshot generation has completed, you can view the results in the normal manner. The following links will be displayed in CAST Enlighten:

Objects

IconDescription

Entity

Entity Operation
Link typeSource and destination of link Methods supported

callLink 

useInsertLink

callLink between the caller .NET Class / Method object and Entity Operation

useInsertLink between the Entity Operation object and Database Table object

  • Add
  • AddAsync
  • AddRange
  • AddRangAsync
  • AddOrUpdate

callLink 

useDeleteLink

callLink between the caller .NET Class / Method object and Entity Operation

useDeleteLink between the Entity Operation object and Database Table object

  • Remove
  • RemoveRange

callLink 

useUpdateLink

callLink between the caller .NET Class / Method object and Entity Operation

useUpdateLink between the Entity Operation object and Database Table object

  • Update
  • UpdateRange
  • AddOrUpdate

callLink 

useSelectLink

callLink between the caller .NET Class / Method object and Entity Operation

useSelecttLink between the Entity Operation object and Database Table object

  • Find
  • FindAsync
  • First
  • FirstOrDefault
  • ToList
  • FirstOrDefaultAsync
  • ToListAsync

Code examples

Insert operation

Insert operation
Add
public void AddNewContractor()        
{
            var contractor = ModelFakes.ContractorFake.Generate();
            var vendor = dbContext.Vendor.FirstOrDefault();
            contractor.VendorId = vendor.Id;
            dbContext.Contractor.Add(contractor);
            dbContext.SaveChanges();
            Assert.AreNotEqual(0, contractor.Id);
}

Delete operation

Delete operation
Delete
public void RemoveEntry()        
{
            var rec = dbContext.Contractor.FirstOrDefault();
            dbContext.Contractor.Remove(rec);
            dbContext.SaveChanges();
}

Update Operation

Update operation
Update
public void UpdateContractorAddress()        
{
            var contractor = dbContext.Contractor.FirstOrDefault();
            contractor.Address = ModelFakes.ContractorFake.Generate().Address;
            dbContext.Contractor.Update(contractor);
            dbContext.SaveChanges();
}         

Select operation

Select operation
Find
public void FindEntry(int id)        
{
            var rec = dbContext.Vendor.Find(id);
            dbContext.SaveChanges();        
}

LINQ-To-Entities

LINQ-To-Entities
LINQ-To-Entities
public static void LinqToEntitiesQueries()
{
         using (var context = new SchoolDBEntities())
         {
		    //Retrieve students whose name is Bill - Linq-to-Entities Query Syntax
                var students = (from s in context.Students
                                where s.StudentName == "Bill"
                                select s).ToList();
                //Retrieve students with the same name - Linq-to-Entities Method Syntax
                var studentsWithSameName = context.Students
                        .GroupBy(s => s.StudentName)
                        .Where(g => g.Count() > 1)
                        .Select(g => g.Key);
          }
}

Support for EntityModelConfiguration

EntityModelConfiguration allows configuration to be performed for any entity type in a model. Support has be been provided to create callLink between method and entity operation object and appropriate crud link between entity operation object and table,  when table name is overridden through EntityModelConfiguration.

EntityModelConfiguration


public DomainModel.Portaalstatus OpslaanLogin(Account account)        
{
            using (new LoggingMonitoredScope(LogConstants.Diagnostics))
            {
                ValidationHelper.Validate(account);
                if (ClaimHelper.IsMeekijker())
                    return new DomainModel.Portaalstatus();
                var cacheKey = CacheSettingsHelper.CreateCacheKey(account);
                                _cacheHelper.Remove(cacheKey, CacheGroups.CacheGroupPortaalStatussen);
                DomainModel.Portaalstatus cacheItem;
                using (var dbContext = new ApfPortalenDbContext())
                {
                    var portaalstatus =
                        dbContext.Portaalstatussen.FirstOrDefault(
                            p => p.AdministratieId.Equals(account.AdministratieIdentificatie) &&
                                 p.RelatienummerDeelnemerMaia.Equals(account.RelatienummerDeelnemerMAIA));
		    if (portaalstatus == null)
                    {
                        portaalstatus = dbContext.Portaalstatussen.Add(new Portaalstatus());
		    }
		}; 
                   
}

Support for CRUD operations using Set<T> 

CRUD using Set <T>

public static void EqualApproch(TestContext testContext)
{
          var dbContext = new EFExamplesDbContext(options);

          dbContext.Set<Vendor>().FirstOrDefault(x => x.NodeId == rootNode.Id);
          dbContext.SaveChanges();
}

Functionality

  • Support is there for both Entity Framework 6 and EntityFramework Core
  • Support for crud operation executed using APIs of DbSet class
  • Support for Asynchronous API and batch operations
  • Support for crud operations executed using Set<T> of DbContext class 
  • Positioning of bookmarks
  • Support for LINQ-to-Entities

Assumptions

  • SaveChanges() method of DbContext class commits the operation in the database table. Hence no useLink is created between caller method and table.
  • When the class is referenced in other code as a property, parent and child relation is created. Any CRUD operation performed on parent class is also reflected in the child class. e.g. In the below case, data is inserted in Contractor, but useInsertLink is created for both Contractor and Vendor tables, as Vendor is referenced in Contractor (foreign key).      

Limitations

  • Analyzing the participating database tables is mandatory for the extension to work correctly