Get from IQueryable to IEnumerable

Jonny Cundall

this should be a quick one for all you f# rockers, but it's got me stuck at the moment.

I've got an F# type which I'm trying to get to implement a c# interface

public interface ICrudService<T> where T: DelEntity, new()
{
    IEnumerable<T> GetAll();
}

here's how it's implemnted in c#:

public IEnumerable<T> GetAll()
{
    return repo.GetAll();
}

repo.GetAll returns an IQueryable, but the c# compiler knows enough to convert to IEnumerable because IQueryable<T> : IEnumerable<T>. but In F# the compiler can't work it and I've tried a few attempt to cast it correctly

type CrudService<'T when 'T :(new : unit -> 'T) and 'T :> DelEntity>(repo : IRepo<'T>) = 
    interface ICrudService<'T> with
         member this.GetAll () = 
            repo.GetAll<'T>

this is giving me a type mismatch error

Lee

You need to cast to IEnumerable<'T>:

type CrudService<'T when 'T :(new : unit -> 'T) and 'T :> DelEntity>(repo : IRepo<'T>) = 
        interface ICrudService<'T> with
             member this.GetAll () = 
                repo.GetAll() :> IEnumerable<'T>

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Get IQueryable from Moq mockset

From Dev

Ambiguous Invocation IQueryable or IEnumerable

From Dev

IQueryable failback to IEnumerable

From Dev

Get IEnumerable from LINQ select

From Dev

Get IEnumerable<SelectListItem> from dbContext

From Dev

Cannot return type IQueryable or IEnumerable

From Dev

IEnumerable<IDictionary<string, object>> to IQueryable

From Dev

IEnumerable can't convert to IQueryable

From Dev

C#: Get distinct T from IEnumerable<IEnumerable<T>>

From Dev

Get data from IEnumerable using IEnumerable<string> as a parameter

From Dev

Get value from IEnumerable foreach loop

From Dev

How to get's the model metadata from an IEnumerable?

From Dev

How to get's the model metadata from an IEnumerable?

From Dev

Get ICollection out from IQueryable<ICollection> LINQ Query

From Dev

ASP.NET MVC 4 get value from IQueryable

From Dev

How to get the where clause from IQueryable defined as interface

From Dev

Extension methods resolution IQueryable vs IEnumerable

From Dev

How to turn an IEnumerable (without type) into an IQueryable<T>?

From Java

Dynamic LINQ OrderBy on IEnumerable<T> / IQueryable<T>

From Java

Returning IEnumerable<T> vs. IQueryable<T>

From Dev

IEnumerable vs IQueryable object - LinQ to SQL

From Dev

Slow AsQueryable() and universal method for IQueryable and IEnumerable

From Dev

Cannot implicitly convert type IEnumerable to IQueryable with Entities

From Dev

How to turn an IEnumerable (without type) into an IQueryable<T>?

From Dev

How to create the IQueryable version of IEnumerable extension method?

From Dev

Using SqlQuery to get IQueryable

From Dev

Flatten IQueryable from IQueryable<IGrouping<int, object>> to IQueryable<object>

From Dev

From IQueryable to TableQuery

From Dev

How to get value from IEnumerable collection using its Key?

Related Related

  1. 1

    Get IQueryable from Moq mockset

  2. 2

    Ambiguous Invocation IQueryable or IEnumerable

  3. 3

    IQueryable failback to IEnumerable

  4. 4

    Get IEnumerable from LINQ select

  5. 5

    Get IEnumerable<SelectListItem> from dbContext

  6. 6

    Cannot return type IQueryable or IEnumerable

  7. 7

    IEnumerable<IDictionary<string, object>> to IQueryable

  8. 8

    IEnumerable can't convert to IQueryable

  9. 9

    C#: Get distinct T from IEnumerable<IEnumerable<T>>

  10. 10

    Get data from IEnumerable using IEnumerable<string> as a parameter

  11. 11

    Get value from IEnumerable foreach loop

  12. 12

    How to get's the model metadata from an IEnumerable?

  13. 13

    How to get's the model metadata from an IEnumerable?

  14. 14

    Get ICollection out from IQueryable<ICollection> LINQ Query

  15. 15

    ASP.NET MVC 4 get value from IQueryable

  16. 16

    How to get the where clause from IQueryable defined as interface

  17. 17

    Extension methods resolution IQueryable vs IEnumerable

  18. 18

    How to turn an IEnumerable (without type) into an IQueryable<T>?

  19. 19

    Dynamic LINQ OrderBy on IEnumerable<T> / IQueryable<T>

  20. 20

    Returning IEnumerable<T> vs. IQueryable<T>

  21. 21

    IEnumerable vs IQueryable object - LinQ to SQL

  22. 22

    Slow AsQueryable() and universal method for IQueryable and IEnumerable

  23. 23

    Cannot implicitly convert type IEnumerable to IQueryable with Entities

  24. 24

    How to turn an IEnumerable (without type) into an IQueryable<T>?

  25. 25

    How to create the IQueryable version of IEnumerable extension method?

  26. 26

    Using SqlQuery to get IQueryable

  27. 27

    Flatten IQueryable from IQueryable<IGrouping<int, object>> to IQueryable<object>

  28. 28

    From IQueryable to TableQuery

  29. 29

    How to get value from IEnumerable collection using its Key?

HotTag

Archive