Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to support dynamic types with EF 6.1? dose EF 7 support dynamic types? #2378

Closed
owidat opened this issue Jun 15, 2015 · 1 comment
Closed

Comments

@owidat
Copy link

owidat commented Jun 15, 2015

We are I build dynamic data context, linq is not support dynamic type we found this solution or workaround
http://jrwren.wrenfam.com/blog/2010/03/04/linq-abuse-with-the-c-4-dynamic-type/

public static class ObjectExtensionMethod
{
public static IEnumerable Select(this object source, Func<dynamic, dynamic> map)
{
foreach (dynamic item in source as dynamic)
{
yield return map(item);
}
}

public static IEnumerable<dynamic> Where(this object source, Func<dynamic, dynamic> predicate)
{
    foreach (dynamic item in source as dynamic)
    {
        if (predicate(item))
            yield return item;
    }
}

}

the problem with this solution is getting all data from database after that applying the where statement. is there any way to apply where statement before getting the data from database with dynamic type.

any suggestions? dose EF 7 support dynamic types so we can look into upgrading our project?

@divega
Copy link
Contributor

divega commented Jun 15, 2015

@owidat As you probably already realized this workaround will not help with LINQ providers that work by translating the LINQ query's expression tree to a server query, since in this case the predicate is not captured as an expression. From what I have heard making dynamic work with that flavor of LINQ query is a pretty hard problem. If some day the language team solves it we can consider supporting it. In the meanwhile there are other patterns we can look into (although not for the EF7 RTM time frame), e.g. those explained in #2282. I would actually like to encourage you to read that issue and provide feedback about what kind of dynamic support you need and why.

In the meanwhile, a solution I have seen applied is to emit strongly typed models at runtime. It is hard to do but it can be made to work with existing frameworks.

@divega divega closed this as completed Jun 15, 2015
@ajcvickers ajcvickers reopened this Oct 16, 2022
@ajcvickers ajcvickers closed this as not planned Won't fix, can't repro, duplicate, stale Oct 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants