用fluentdata+webform做一个简单项目(2)-FluentData核心功能

选择FluentData,主要看中其可以自动将sql查询结果映射为指定对象。

举个例子来讲:

public class Deal 
{
    public int DealId { get; set; }
    public string Title { get; set; }
    public int FKProviderid { get; set; }
    public virtual Provider Provider { get; set; }
}

public class Provider
{
    public int ProviderId { get; set; }
    public string Name { get; set; }
}
使用FluentData如下的语句:

DbContext.Sql("select a.*,b.Name as Provider_Name from Deal a inner join Provider b on a.FKProviderId=b.ProviderId").QueryMany<Deal>();

返回一个List<Deal>并且每个Deal对象的Provider属性都会自动创建为Provider对象,并且为对象的Name赋值

FluentData可以下载到源码,但代码太多不好理解,我在下面实现了sqldatareader映射的功能,大概可以体现FluentData的实现方式:

using System;
using System.Collections;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using System.Web;

/// <summary>
/// 反射辅助类
/// </summary>
public static class ReflectionHelper
{
    private static readonly ConcurrentDictionary<Type, Dictionary<string, PropertyInfo>> _cachedProperties 
        = new ConcurrentDictionary<Type, Dictionary<string, PropertyInfo>>();

    public static object GetPropertyValue(object item, PropertyInfo property)
    {
        var value = property.GetValue(item, null);

        return value;
    }

    public static Dictionary<string, PropertyInfo> GetProperties(Type type)
    {
        var properties = _cachedProperties.GetOrAdd(type, BuildPropertyDictionary);

        return properties;
    }

    private static Dictionary<string, PropertyInfo> BuildPropertyDictionary(Type type)
    {
        var result = new Dictionary<string, PropertyInfo>();

        var properties = type.Get
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Webform项目一个用于创建和管理在线表格和调查的开源项目。它是一个基于Drupal的模块,可以让用户通过简单易用的界面设计和修改各种类型的表单,包括联系表单、注册表格、调查问卷等。Webform项目的源码包含了各种功能模块和程序代码,用于实现表单的创建、保存、展示和提交等功能Webform项目的源码主要包括以下几个部分:表单设计和布局模块、数据存储和处理模块、用户界面和交互模块。其中,表单设计和布局模块包括了各种可视化编辑工具和模板,帮助用户设计出自己想要的表单样式和布局结构;数据存储和处理模块则负责将用户提交的表单数据保存到数据库中,并提供数据处理和分析的功能;用户界面和交互模块则是用于展示和交互用户提交的表单数据,包括表单预览、提交反馈等。 Webform项目的源码是基于PHP语言编写的,它使用了Drupal的框架和模块体系,因此在使用时需要依赖Drupal环境。用户可以通过下载Webform项目的源码,并将其部署到自己的Drupal系统中,然后根据自己的需要进行二次开发和定制。同时,Webform项目也提供了丰富的文档和社区支持,方便用户学习和使用。 总的来说,Webform项目的源码是一个功能丰富、易扩展的开源项目,它为用户提供了方便快捷的在线表单设计和管理解决方案,适用于各种类型的网站和应用程序。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值