[开源] .Net ORM 访问 Firebird 数据库

前言

Firebird 是一个跨平台的关系数据库系统,目前能够运行在 Windows、linux 和各种 Unix 操作系统上,提供了大部分 SQL-99 标准的功能。它既能作为多用户环境下的数据库服务器运行,也提供嵌入式数据库的实现。

Firebird 脱胎于 Borland 公司的开源版数据库 Interbase6.0,是一个完全非商业化的产品,用 C 和 C++ 开发。由于与 interbase 的血缘关系,大部分 interbase 的开发工具可以直接应用到 Firebird 开发中。Firebird 使用 Mozilla Public License v.1.1 许可证发行。

FreeSql 支持 Firebird 嵌入式数据库,与 Sqlite 一样属于本地数据库,并且可靠性强于 sqlite,数据库文件不过 10兆 大小。

1、安装环境

数据库环境:Firebird (嵌入式版本)

下载地址:https://firebirdsql.org/en/server-packages/

.NET版本:.net6.0

下载地址:https://dotnet.microsoft.com/learn/dotnet/hello-world-tutorial/install

开发机器 :windows 10

2、创建项目

我们以 console 类型项目试验 插入、删除、更新、查询 等功能,创建控制台项目,使用命令:

dotnet new console

dotnet add package FreeSql.Provider.Firebird

dotnet add package FreeSql.Repository

3、创建实体模型

using System;
using FreeSql.DataAnnotations;

[Table(Name = "USER_FIREBIRD")]
public class User
{
    [Column(IsIdentity = true)]
    public long Id { get; set; }

    public string UserName { get; set; }

    public string PassWord { get; set; }

    public DateTime CreateTime { get; set; }
}

4、初始化 ORM

static IFreeSql fsql = new FreeSql.FreeSqlBuilder()
    .UseConnectionString(FreeSql.DataType.Firebird, 
    @"database=localhost:D:\fbdata\EXAMPLES.fdb;user=sysdba;password
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Dapper .NET 是 .NET 下一个简单的对象关系映射库 (ORM)。它支持SQLite, SQL CE, Firebird, Oracle, MySQL, PostgreSQL and SQL Server等数据库。   优点: 使用Dapper可以自动进行对象映射! 轻量级,单文件。 支持多数据库。 Dapper原理通过Emit反射IDataReader的序列队列,来快速的得到和产生对象。   Dapper.Net的示例代码: public class Dog {     public int? Age { get; set; }     public Guid Id { get; set; }     public string Name { get; set; }     public float? Weight { get; set; }     public int IgnoredProperty { get { return 1; } } }             var guid = Guid.NewGuid(); var dog = connection.Query("select Age = @Age, Id = @Id", new { Age = (int?)null, Id = guid }); dog.Count()     .IsEqualTo(1); dog.First().Age     .IsNull(); dog.First().Id     .IsEqualTo(guid); 下面是Dapper .NET与其他几种数据访问组件的性能对比,从比较结果看Dapper .NET表现优异。 Performance of SELECT mapping over 500 iterations - POCO serialization Method Duration Remarks Hand coded (using a SqlDataReader) 47ms Can be faster Dapper ExecuteMapperQuery 49ms ServiceStack.OrmLite (QueryById) 50ms PetaPoco 52ms BLToolkit 80ms SubSonic CodingHorror 107ms NHibernate SQL 104ms Linq 2 SQL ExecuteQuery 181ms Entity framework ExecuteStoreQuery 631ms Performance of SELECT mapping over 500 iterations - dynamic serialization Method Duration Remarks Dapper ExecuteMapperQuery (dynamic) 48ms   Massive 52ms Simple.Data 95ms Performance of SELECT mapping over 500 iterations - typical usage Method Duration Remarks Linq 2 SQL CompiledQuery 81ms Not super typical involves complex code NHibernate HQL 118ms   Linq 2 SQL 559ms   Entity framework 859ms   SubSonic ActiveRecord.SingleOrDefault         github地址:https://github.com/StackExchange/dapper-dot-net 入门教程:http://www.cnblogs.com/Sinte-Beuve/p/4231053.html   Dapper已经有很多成熟的扩展项目了,Dapper.Rainbow、Dapper.Contrib,DapperExtensions   其中Dapper-Extensions非常不错,github地址:https://github.com/tmsmith/Dapper-Extensions Dapper-Extensions的优点: 1、开源 2、针对Dapper封装了常用的CRUD方法,有独立的查询语法。 3、需要映射的实体类本身0配置,无需加特性什么的。是通过独立的映射类来处理,可以设置类映射到DB的别名,字段的别名等等。 Dapper-Extensions的缺点: 1、好几年没更新了 2、不支持oracle(木有oracle的方言,已经搞定)  3、不能同时支持多种数据库(已经搞定) 4、部分代码有些bug(发现的都搞定了)   Dapper-Extensions入门教程可参考: http://www.cnblogs.com/hy59005271/p/4759623.html       标签:orm

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值