惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

罗磊的独立博客
Cisco Talos Blog
Cisco Talos Blog
C
Check Point Blog
博客园_首页
Recent Commits to openclaw:main
Recent Commits to openclaw:main
Martin Fowler
Martin Fowler
Recorded Future
Recorded Future
S
Security @ Cisco Blogs
L
LINUX DO - 最新话题
博客园 - 司徒正美
P
Privacy International News Feed
G
Google Developers Blog
I
Intezer
Hacker News - Newest:
Hacker News - Newest: "LLM"
博客园 - 聂微东
The GitHub Blog
The GitHub Blog
C
Cybersecurity and Infrastructure Security Agency CISA
www.infosecurity-magazine.com
www.infosecurity-magazine.com
Scott Helme
Scott Helme
K
Kaspersky official blog
I
InfoQ
Y
Y Combinator Blog
T
The Blog of Author Tim Ferriss
Webroot Blog
Webroot Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
大猫的无限游戏
大猫的无限游戏
D
Docker
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
W
WeLiveSecurity
Microsoft Azure Blog
Microsoft Azure Blog
Spread Privacy
Spread Privacy
量子位
H
Hacker News: Front Page
Simon Willison's Weblog
Simon Willison's Weblog
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
SecWiki News
SecWiki News
S
Security Affairs
Latest news
Latest news
人人都是产品经理
人人都是产品经理
C
CERT Recently Published Vulnerability Notes
S
Security Archives - TechRepublic
V
Visual Studio Blog
T
Troy Hunt's Blog
S
Secure Thoughts
F
Fortinet All Blogs
V
V2EX
The Register - Security
The Register - Security
J
Java Code Geeks
MongoDB | Blog
MongoDB | Blog
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO

博客园 - faib

代码生成器(CodeBuilder) 2.9.4 稳定版 代码生成器(CodeBuilder) 2.9.3 稳定版 Fireasy新版本发布 Winform快速开发组件的实现(二) Winform快速开发组件的实现(一) 注意Activator.CreateInstance两个重载方法的性能 Fireasy.Data系列——发布测试版本 Fireasy.Data系列——线程内IDatabase的传递 Fireasy.Data系列——数据库架构的整合查询 Fireasy.Data系列——数据库提供者的插件服务簇 Fireasy.Data系列——几种数据库的大数据批量插入 Fireasy.Data系列——底层结构 Fireasy.Data系列——概述 轻量的Json序列化 ReSharper 不为人知的罪恶选项 AxTools.VS10x.CodeMap注册机 3个月时间完成工作流项目 历时半年,发布最完整的代码生成器CodeBuilder最新版本 最新版本的CodeBuilder 1.0.0.1446
我想组建新的Entity框架
faib · 2011-10-01 · via 博客园 - faib

    这个想法已经有很长一段时间了,并且目前已经有一个雏形的版本了,我暂定它为Fireasy.Data.Entity。

    我先说一说我的想法,实体的映射将采用依赖属性的方式进行定义,这样可以避免使用反射进行实体的初始化,而且也比较实现其他代码的切入。

    在这个框架里,还是提供了引用实体和实体集的概念,它们也可以通过lazy加载进来,另外,还设计一个支持枚举的属性和一个同步属性。

    另外,根据实际项目的需要,还会将同一个实体根据不同的规则映射多个不同的数据表,以提供数据分布式和隔离式存储。还会提供一个树结构的映射及相应的持久化类,以达到快速应用。

    实体的继承特性将在下一期进行考虑。

    以下是实体类的代码示例:

    [EntityMapping("PRODUCTS")]
    public class Product : EntityObject
    {
        public readonly static IProperty _ProductId = PropertyUnity.RegisterProperty("ProductId"
            typeof(int), typeof(Product), 
            new PropertyMapInfo
            {
                FieldName = "PRODUCTID",
                GenerateType = IdentityGenerateType.AutoIncrement,
                IsPrimaryKey = true,
                IsNullable = false
            });

        public readonly static IProperty _ProductName = PropertyUnity.RegisterProperty("ProductName"
            typeof(string), typeof(Product), 
            new PropertyMapInfo
            {
                FieldName = "PRODUCTNAME",
                IsNullable = false
            });

        public readonly static IProperty _SupplierID = PropertyUnity.RegisterProperty("SupplierID"
            typeof(int?), typeof(Product), 
            new PropertyMapInfo { FieldName = "SUPPLIERID" });

        public readonly static IProperty _CategoryID = PropertyUnity.RegisterProperty("CategoryID"
            typeof(int?), typeof(Product), 
            new PropertyMapInfo { FieldName = "CATEGORYID" });

        public readonly static IProperty _QuantityPerUnit = PropertyUnity.RegisterProperty("QuantityPerUnit"
            typeof(string), typeof(Product), 
            new PropertyMapInfo { FieldName = "QUANTITYPERUNIT" });

        public readonly static IProperty _UnitPrice = PropertyUnity.RegisterProperty("UnitPrice"
            typeof(decimal?), typeof(Product), 
            new PropertyMapInfo { FieldName = "UNITPRICE" });

        public readonly static IProperty _UnitsInStock = PropertyUnity.RegisterProperty("UnitsInStock"
            typeof(short?), typeof(Product), 
            new PropertyMapInfo { FieldName = "UNITSINSTOCK" });

        public readonly static IProperty _UnitsOnOrder = PropertyUnity.RegisterProperty("UnitsOnOrder"
            typeof(short?), typeof(Product), 
            new PropertyMapInfo { FieldName = "REORDERLEVEL" });

        public readonly static IProperty _ReorderLevel = PropertyUnity.RegisterProperty("ReorderLevel"
            typeof(short?), typeof(Product), 
            new PropertyMapInfo { FieldName = "REORDERLEVEL" });

        public readonly static IProperty _Discontinued = PropertyUnity.RegisterProperty("Discontinued"
            typeof(bool?), typeof(Product),
            new PropertyMapInfo { FieldName = "DISCONTINUED", DefaultValue = true });

        public readonly static IProperty _OrderDetails = PropertyUnity.RegisterSpecialProperty("OrderDetails"
            typeof(EntitySet<OrderDetails>), typeof(Product));

        public readonly static IProperty _DelFlag = PropertyUnity.RegisterProperty("DelFlag"
            typeof(bool?), typeof(Product), new PropertyMapInfo { FieldName = "DEL_FLAG", IsFakeDeleteFlag = true });

        public int ProductId
        {
            get { return (int)GetValue(_ProductId); }
            set { SetValue(_ProductId, value); }
        }

        public string ProductName
        {
            get { return (string)GetValue(_ProductName); }
            set { SetValue(_ProductName, value); }
        }

        public int? SupplierID
        {
            get { return (int)GetValue(_SupplierID); }
            set { SetValue(_SupplierID, value); }
        }

        public int? CategoryID
        {
            get { return (int)GetValue(_CategoryID); }
            set { SetValue(_CategoryID, value); }
        }

        public string QuantityPerUnit
        {
            get { return (string)GetValue(_QuantityPerUnit); }
            set { SetValue(_QuantityPerUnit, value); }
        }

        public decimal? UnitPrice
        {
            get { return (decimal)GetValue(_UnitPrice); }
            set { SetValue(_UnitPrice, value); }
        }

        public short? UnitsInStock
        {
            get { return (Int16)GetValue(_UnitsInStock); }
            set { SetValue(_UnitsInStock, value); }
        }

        public short? UnitsOnOrder
        {
            get { return (Int16)GetValue(_UnitsOnOrder); }
            set { SetValue(_UnitsOnOrder, value); }
        }

        public short? ReorderLevel
        {
            get { return (Int16)GetValue(_ReorderLevel); }
            set { SetValue(_ReorderLevel, value); }
        }

        public bool? Discontinued
        {
            get { return (bool)GetValue(_Discontinued); }
            set { SetValue(_Discontinued, value); }
        }

        public EntitySet<OrderDetails> OrderDetails
        {
            get { return (EntitySet<OrderDetails>)GetValue(_OrderDetails); }
            set { SetValue(_OrderDetails, value); }
        }

        public bool? DelFlag
        {
            get { return (bool)GetValue(_DelFlag); }
            set { SetValue(_DelFlag, value); }
        }

    }

与EF相似地,实体间的关系采用Assembly特性进行定义:

[assembly: Relationship("Product:OrderDetails"typeof(Product), typeof(OrderDetails), "ProductId=>ProductId")]
[assembly: Relationship("Orders:OrderDetails"typeof(Orders), typeof(OrderDetails), "OrderID=>OrderId")]
[assembly: Relationship("Customer:Orders"typeof(Customers), typeof(Orders), "CustomerID=>CustomerID")]

    框架也提供对Linq查询的支持,目前支持mssql、oracle、mysql和sqlite几种数据库。

    目前的测试结果显示,数据加载的速度比EF稍稍快了一点点,现在需要请大虾帮忙验证这种方式的可行性。也请有兴趣的朋友一起加入讨论,多给我提些意见。QQ群号:6406277。