021.EntityFramework/EntityFrameworkHelper.cs
(开头部分) 27KB这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。
#region -- 版 本 注 释 --
/****************************************************
* 文 件 名:
* Copyright(c) 王树羽
* CLR 版本: 4.5
* 创 建 人:王树羽
* 电子邮箱:674613047@qq.com
* 官方网站:https://www.cnblogs.com/shuyu
* 创建日期:2018-06-25
* 文件描述:
******************************************************
* 修 改 人:
* 修改日期:
* 备注描述:
*******************************************************/
#endregion
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Data.Entity.Infrastructure;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using System.Text;
namespace CommonLib
{
/// <summary>
/// EntityFramework 开发帮助类
/// </summary>
public static class EntityFrameworkHelper
{
#region EntityFramework
#region 添加
/// <summary>
/// 添加
/// </summary>
/// <typeparam name="T">类型</typeparam>
/// <param name="DB">DbContext上下文对象</param>
/// <param name="entity">实体对象</param>
/// <returns></returns>
public static int ExAdd<T>(this DbContext DB, T entity) where T : class
{
#region 设置默认值
Type t = typeof(T);
PropertyInfo[] propInfos = t.GetProperties();
foreach (var pi in propInfos)
{
if (pi.Name.ToUpper() == "GUID")
{
var value = pi.GetValue(entity, null);
if (value.ToString() == Guid.Empty.ToString())
{
pi.SetValue((T)entity, Guid.NewGuid(), null);
}
后面还有 723 行代码,解锁后查看完整代码
24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明
AI 解读
登录后可用,每次 10 积分,解读结果公开显示在下面。
还没有人解读过这个文件。
