基于EF6的快速开发Web框架——Swift.Net

本文介绍Swift.Net,一种轻量级、快速的.NET框架。通过创建实体类、映射类、仓库类和服务类,实现数据操作。文章提供了详细步骤和示例代码,并附上源码地址和配置信息。

Swift.Net

This Is A Light-Weight And Fast-Develop .Net Framework.

Usage

STEP 1 Create Your Entities

public class DemoEntity : BaseEntity
{
  public int Id { get; set; }
  public string Name { get; set; }
  public string Phone { get; set; }
  public string Nric { get; set; }
  public int Age { get; set; }
  public float Height { get; set; }
  public int? Sex { get; set; }
}

STEP 2 Create The Mapper

Put this Mappers into the Mapper Directory which In Entity Project.

public class DemoEnityMapper : BaseMap<DemoEntity>
   {
       public override void Init()
       {
          ToTable("DemoEntity");
          HasKey(m => m.Id);
       }

   }

STEP 3 Create The Resposity

public class DemoResp : BaseRep<DemoEntity>
{

}

STEP 4 Create The Service

public class DemoSvc : BaseSvc<DemoEntity>
{
  DemoResp dr = new DemoResp();
  public int AddEntity(DemoEntity obj)
  {
    return Add(obj);
  }
}

STEP 5 So,We Test

Now We Just Config This:

<connectionStrings>
  <add name="DbConnection" connectionString="Data Source=.;Initial Catalog=SwiftNet;User ID=sa;Password=sa"
  providerName="System.Data.SqlClient" />
</connectionStrings>

And This:

<appSettings>
  <!--实体程序集名称-->
  <add key="SwiftEntityAssembly" value="Swift.Demo.Entity"/>
  <!--是否自动创建数据库,此配置可以省略,省略则默认创建数据库-->
  <add key="SwiftCreateDb" value="true"/>
</appSettings>

Now,Test:

public void TestMethod1()
{
  var svc = new DemoSvc();
  var obj = new DemoEntity {
                Name = "jerry",
                Nric = "32148461641649616",
                Phone = "189615645",
                Age = 1111,
                Height = 234,
                Sex = 1,
                Remark = "这是一个备注",
            };
  var res = svc.AddEntity(obj);
}

源码地址:https://github.com/decadestory/Swift.net

转载于:https://www.cnblogs.com/JerryNo1/p/5061456.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值