Giter Site home page Giter Site logo

Comments (6)

UtilCore avatar UtilCore commented on August 27, 2024

@maverickljw 你好,代理对象的问题确实非常麻烦,我没有找到好的办法来判断是否是代理,有一种丑陋的办法是查找对象名称是否包含特定关键字。你能提供EF代理对象的样例名称吗,多给几个。

from util.

maverickljw avatar maverickljw commented on August 27, 2024

代理对象Type的full name举例:
u.GetType().FullName
"System.Data.Entity.DynamicProxies.User_8F682D0B0A658523C6F71898F12F31FA72950F1CAC8108C028176279FD8E50BE"

我看了一下,如果是代理对象的话,其BaseType指向了原本的对象,如下:
u.GetType().BaseType
{Name = "User" FullName = "Mavercloud.OnlinePublication.DataEntities.Entities.User"}

应该可以根据这个来:)

from util.

UtilCore avatar UtilCore commented on August 27, 2024

@maverickljw 请问你是用的EF还是EF Core?

from util.

maverickljw avatar maverickljw commented on August 27, 2024

EF

from util.

UtilCore avatar UtilCore commented on August 27, 2024

@maverickljw 我这用的EF CORE,没这问题呢,你如果修复了这个问题,提交一个pr吧

from util.

maverickljw avatar maverickljw commented on August 27, 2024

抱歉,暂时还无法提交pr,先把我改的地方标识一下吧(比较丑陋的方法,暂时符合我这边的情况):

private static Type GetType( object obj ) {
var type = obj.GetType();
if ((obj is System.Collections.IEnumerable) == false)
if (type.FullName.StartsWith("System.Data.Entity.DynamicProxies"))
{
return type.BaseType;
}
else
{
return type;
}

if( type.IsArray )
return type.GetElementType();
var genericArgumentsTypes = type.GetTypeInfo().GetGenericArguments();
if( genericArgumentsTypes == null || genericArgumentsTypes.Length == 0 )
throw new ArgumentException( "泛型类型参数不能为空" );
return genericArgumentsTypes[0];
}

from util.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.