Skip to content
quick-gate edited this page May 22, 2019 · 5 revisions

Welcome to the Enterprise Application Framework (Eaf) Project Wiki

Eaf is metadata framework for building persistent entity based systems like ERP, CRM, E-Commerce ....

Workflow

What you do

  • Create entities
    public class Product
    {
        public int Id { get; set; }
        public string Code { get; set; }
        public string Barcode { get; set; }
        public bool IsActive { get; set; }
        public string SerialNumber { get; set; }
        public IList<ProductTranslation> Translations { get; set; }
    }
  • Create multi-language metadata model
    public class ProductDescriptor : EntityDescriptor<Product>
    {
        public AttributeMetadata Id { get; set; } = new AttributeMetadata
        {
            Name = nameof(Product.Id),
            IsKey = true,
            Type = new AttributeType
            {
                DataType = AttributeDataType.Integer
            },
            Translations = new List<AttributeMetadataTranslation>
            {
                new AttributeMetadataTranslation
                {
                    Caption = "Id",
                    LanguageCode = LanguageCodes.en
                },
                new AttributeMetadataTranslation
                {
                    Caption = "Id",
                    LanguageCode = LanguageCodes.cs
                }
            }
        };

        public AttributeMetadata Code { get; set; } = new AttributeMetadata
        {
            Name = nameof(Product.Code),
            Type = new AttributeType
            {
                DataType = AttributeDataType.String,
                Length = 150
            },
            Translations = new List<AttributeMetadataTranslation>
                {
                    new AttributeMetadataTranslation
                    {
                        LanguageCode = LanguageCodes.en,
                        Caption = "Product Code"
                    },
                    new AttributeMetadataTranslation
                    {
                        LanguageCode = LanguageCodes.cs,
                        Caption = "Kód produktu"
                    }
                }
        };

What Eaf Do

  • Create and Migrate Database structure
  • Seed Data
  • Create ORM mapping
_eafDataContext.Save(product);
_eafDataContext.Delete(product);
_eafDataContext.Products.FirstOrDefault(x=>x.Code == "12345" && x.IsActive);
  • Create Data Management UI

  • Create Simple Metadata Query Model
ProductMetadata.Instance
.Select(x.Id, x.Code, x.Translations.Name)
.Where(x.Code.Eq("Test")).And(x.MainCategory.Code.NotNullOrEmpty)
.OrderBy(x.MainCategory.Order);

//Linq Future (not implemented)
var products = new Query<Product>()
.Select(x=>x.Id, x.Code, x.Translations.Name)
.Where(x=>x.IsActive && x.Translations.Language == "en")
.OrderBy(x=>x.Name).ToList();

Getting Started with ASP.NET Core APP

  • Add reference to EAF Framework
  • If you want use EF Core Migration install NuGet Microsoft.EntityFrameworkCore.Design
  • Create your Domain and Descriptor Classes
  • Configure EAF framework in ASP.NET Startup file

` private const string CorsPolicyName = "AllowAllCorsPolicy";

    public void ConfigureServices(IServiceCollection services)
    {
        services.AddMvc()
            .AddNewtonsoftJson(x =>
            {

//You can set as you need x.SerializerSettings.ContractResolver = new DefaultContractResolver(); x.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore; });

        services
            .AddEaf()
            .AddMetadataAssemblies(typeof(Product).Assembly) //Add assembly which contains Eaf Descriptors

//Set your connection string .AddDataContext("Server=(local);Database=E-Commerce;Uid=sa;Pwd=******");

        services.AddCors(options =>
        {
            options.AddPolicy(CorsPolicyName,
            builder =>
            {

// For production set right Origins builder .AllowAnyOrigin() .AllowAnyHeader() .AllowAnyMethod(); }); });

.....

    public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
    {

...

        //Add to documentation
        app.UseCors(CorsPolicyName);

... `

Clone this wiki locally