PetaPoco - 1.0
Extension ID
com.castsoftware.dotnet.petapoco
What’s new?
Please see Release Notes for more information.
Description
This extension provides support for the PetaPoco and NPoco .NET frameworks.
In what situation should you install this extension?
This extension should be installed when analyzing a .NET project that uses the Petapoco/NPoco framework, and you want to view CRUD transactions of the NPoco objects. Links to corresponding SQL database tables can also be resolved, provided that the SQL database has been extracted and DDL has been created.
Technology support
The following libraries are supported by this extension:
Language | Library name | Namespace | Version | Supported |
---|---|---|---|---|
C# | PetaPoco | PetaPoco | Up to 6.x | ✅ |
C# | NPoco | NPoco | Up to 5.x | ✅ |
Compatibility
CAST Imaging Core release | Supported |
---|---|
8.4.x | ✅ |
8.3.x | ✅ |
Download and installation instructions
For applications using any of the above mentionned libraries, this extension will be automatically installed. For upgrade, if the Extension Strategy is not set to Auto Update, you can manually upgrade the extension.
What results can you expect?
Once the analysis/snapshot generation has completed, you can view the below objects and links created.
Objects
Icon | Description | Comment |
---|---|---|
NPoco Entity | An object is created for each PetaPoco/NPoco Persistent Object | |
NPoco Entity Operation | An object is created for each PetaPoco/NPoco Persistent Object CRUD operation | |
NPoco Unknown Entity | An object is created for when PetaPoco/NPoco Persistent Object cannot be resolved | |
NPoco Unknown Entity Operation | An object is created for each PetaPoco/NPoco Persistent Object CRUD operation and respective Entity cannot be resolved | |
NPoco SQL Query | An object is created for each direct SQL query operation found in PetaPoco/NPoco project and resolved in a method call | |
NPoco Unknown SQL Query | An object is created for each direct SQL query found in PetaPoco/NPoco project and the exact query cannot be resolved |
Links
Link Type | Caller | Callee | APIs Supported |
---|---|---|---|
callLink | C# Method | NPoco Entity Operation NPoco Unknown Entity Operation |
PetaPoco.Database.Insert PetaPoco.Database.Update NPoco.Database.UpdateAsync NPoco.Database.UpdateMany NPoco.Database.UpdateManyAsync PetaPoco.Database.Delete PetaPoco.Database.Exists PetaPoco.Database.Save NPoco.Database.Insert NPoco.Database.InsertAsync NPoco.Database.InsertBulk NPoco.Database.InsertBulkAsync NPoco.Database.InsertBatch NPoco.Database.InsertBatchAsync NPoco.Database.SingleById NPoco.Database.SingleOrDefaultById NPoco.Database.Update NPoco.Database.Delete NPoco.Database.DeleteAsync NPoco.Database.DeleteMany NPoco.Database.DeleteManyAsync NPoco.Database.Exists NPoco.Database.IsNew NPoco.Database.Save NPoco.Database.SaveAsync |
callLink | C# Method | NPoco SQL Query NPoco Unknown SQL Query |
PetaPoco.Database.SingleOrDefault PetaPoco.Database.Single PetaPoco.Database.FirstOrDefault PetaPoco.Database.First PetaPoco.Database.Fetch PetaPoco.Database.Query PetaPoco.Database.Page PetaPoco.Database.Delete PetaPoco.Database.Execute NPoco.Database.Single NPoco.Database.SingleAsync NPoco.Database.SingleOrDefault NPoco.Database.First NPoco.Database.FirstAsync NPoco.Database.FirstOrDefault NPoco.Database.Fetch NPoco.Database.FetchAsync NPoco.Database.Query NPoco.Database.Page NPoco.Database.PageAsync NPoco.Database.Delete NPoco.Database.Execute NPoco.Database.ExecuteAsync |
useLink | NPoco Entity Operation | Table, View | Created by SQLAnalyzer when DDL source files are analyzed |
callLink | NPoco Entity Operation | Procedure | Created by SQLAnalyzer when DDL source files are analyzed |
useLink | NPoco SQL Query | Table, View | Created by SQLAnalyzer when DDL source files are analyzed |
callLink | NPoco SQL Query | Procedure | Created by SQLAnalyzer when DDL source files are analyzed |
Examples
Persistent Objects CRUD
Entity Object
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using PetaPoco;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel;
namespace PetaPocoWebTest.Poco
{
[TableName( "tag")]
public class Tag
{
public int Id {get; set;}
[Column( "tagName")]
public string TagName {get; set;}
public Tag() : this( string.Empty)
{
}
[ResultColumn]
public List<Article> Articles {get; set;}
public override string ToString()
{
return this.TagName;
}
public Tag( string tagName)
{
this.TagName = tagName;
this.Id = int.MinValue;
this.Articles = new List<Article>();
}
}
}
Insert Operation
using SubSonic;
public bool Insert( Tag tag)
{
_database.Insert( "tag", "id", true, tag);
return true;
}
Update Operation
public bool Update( Tag tag)
{
_database.Update( tag);
return true;
}
Select Operation
public bool TagExists(int tagId)
{
return _database.Exists<Tag>(tagId);
}
Delete Operation
public bool Delete_entity(Tag tag)
{
using (var scope = _database.GetTransaction())
{
int rowsAffected = _database.Delete(tag);
if (rowsAffected > 0)
{
scope.Complete();
return true;
}
else
{
return false; // Deletion failed or the entity did not exist
}
}
}
Query Operation
public List<Tag> RetrieveAll()
{
return _database.Fetch<Tag, Article, Author, Tag>(
new TagRelator().Map,
"select * from tag " +
"left outer join articleTag on articleTag.tagId = tag.id " +
"left outer join article on article.id = articleTag.articleId " +
"join author on author.id = article.author_id order by tag.tagName asc").ToList();
}