How to return Task<IEnumerable<T>>?

How to return Task<IEnumerable<T>>?

By : lsrusty
Date : November 20 2020, 07:00 PM
I wish this help you If you have a regular IEnumerable, so not as a result of another task method.
You can return it like this.
code :
return Task.FromResult(Enumerable.Empty<MyClass>());
return Task.FromResult(myResult);

Share : facebook icon twitter icon
AutoFixture auto setup return type of Task<IEnumerable<>> customization

AutoFixture auto setup return type of Task<IEnumerable<>> customization

By : user3279218
Date : March 29 2020, 07:55 AM
help you fix your problem AutoFixture already supports Tasks out of the box, as evidenced by this Characterization Test:
code :
public void AutoFixtureAlreadySupportsTasks()
    var fixture = new Fixture();
    var t = fixture.Create<Task<IEnumerable<int>>>();
public void ConfigureMock()
    var fixture = new Fixture().Customize(new AutoMoqCustomization());
        .Setup(s => s.Get())

    var svc = fixture.Create<ISomeService>();

public void SimplestCustomization()
    var fixture = 
        new Fixture().Customize(new AutoConfiguredMoqCustomization());
    var svc = fixture.Create<ISomeService>();
Mapper.Map<Task<IEnumerable<Address>>, Task<IEnumerable<AddressView>>()

Mapper.Map<Task<IEnumerable<Address>>, Task<IEnumerable<AddressView>>()

By : go giap
Date : March 29 2020, 07:55 AM
Any of those help You should not be trying to map a Task - await the result of the task and map that:
code :
public async Task<IEnumerable<AddressModel>> GetAllAsync()
    AddressService service = new AddressService(new DataContext());
    IEnumerable<Address> data = await service.GetAllAddressesAsync();
    var addressList = Mapper.Map<IEnumerable<AddressModel>>(data);

    return addressList;
How to return an action result of async Task<IEnumerable<SomeClass>>?

How to return an action result of async Task<IEnumerable<SomeClass>>?

By : open64
Date : March 29 2020, 07:55 AM
it helps some times I have this code but the controller is expecting a return type of ActionResult. Why is the controller is accepting a Task> like this return await _context.Users.ToListAsync();(the default code when a controller is generated)? , I believe you need something like:
code :
public async Task<ActionResult<IEnumerable<User>>> MyController()
    var res = await _userService.GetAll();

    if (res == null)
        return NotFound();

    return Ok(res);
async Task<IEnumerable> with yield return?

async Task<IEnumerable> with yield return?

By : Haas Krishna
Date : March 29 2020, 07:55 AM
Hope that helps Based on @SLaks's comment to the question, here's a general alternative using Reactive Extensions:
C# how to combine 2 Task<IEnumerable<T>> via Union and return task

C# how to combine 2 Task<IEnumerable<T>> via Union and return task

By : adi vardam
Date : March 29 2020, 07:55 AM
Any of those help
If the IEnumerables weren't wrapped in Tasks, of course I would just do:
code :
var ResultC = ResultA.Union(ResultB);
Task<IEnumerable<T>> resultA = whatever;
Task<IEnumerable<T>> resultB = whatever;
Func<Task<IEnumerable<T>>> getTaskC = 
  async () => (await resultA).Union(await resultB); 
Task<IEnumerable<T>> resultC = getTaskC();
Related Posts Related Posts :
  • Entity Framework Polymorphism
  • sendmail function shows:Syntax error, command unrecognized. The server response was:
  • WPF - How to bind a DataGridTemplateColumn
  • How to use Linq group a order list by Date
  • Sending SMS using free gateway
  • Support for VB.NET's Imported Namespaces feature in C#
  • Comparing multiple entity properties against list of entities
  • Accessing a master page from httphandler
  • how to increase speed of my execution
  • Hard Coded Paths in a .NET Program
  • .NET sendkeys to calculator
  • MVVM and Ribbon Command
  • Dropdownlist and Datareader
  • How to programmatically self delete? (C# WinMobile)
  • using Linq to partition data into arrays
  • Returning the PK during a linq to sql insert
  • VSTO Alternatives
  • A regular expression that will allow a string with only one Capital Letter
  • object reference not set to an instance of object exception coming at runtime
  • Resizing a monochromatic image in C#
  • How to determine user DN after authentication against an Active Directory?
  • Sharing a COM port over TCP
  • Reading an XML File with .NET
  • Multiplayer game
  • How to equal two strings case sensitively in Linq to SQL?
  • How do you stream text to an IRC Channel
  • How to reduce this IF-Else ladder in c#
  • Integration Test Example With Rhino Mocks
  • My User control belonging to which Design Pattern?
  • How do I extract a substring from a string until the second space is encountered?
  • DataContractJsonSerializer set value extension point
  • I am adding a new splistitem to a sharepoint list but it always gives me an exception: "object reference not set to
  • TextRenderer.DrawText renders Arial differently on XP vs Vista
  • Are there any implementations of multiset for .Net?
  • Multithreading Errors in C#
  • What happens with TCP packets between two Socket.BeginReceive calls?
  • Simple multi-threading - combining statements to two lines
  • Dice face value recognition
  • Unit test class inherited from ContextBoundObject and decorated with ContextAttribute
  • C# design question (Connections)
  • Maintain the SessionID for Entire Application in ASP.NET
  • .NET substitute dependent assemblies without recompiling?
  • C# PDF Control & Library
  • Linq help using "Contains"
  • .net equivalent of htmlunit?
  • required files to distribute a .net application
  • C# Int and math not returning full value
  • Reading XML using XDocument & Linq - check if element is NULL?
  • How do I invoke a MethodInfo that was created from an anonymous method?
  • .Net C# : Read attachment from HttpWebResponse
  • Placing and removing element on array trough object
  • Editing 8bpp indexed Bitmaps
  • How do I draw a graduated border on a polygon using GDI+ via C#/WinForms?
  • Sequential (comb) GUIDs for Oracle
  • How do I separate routes that have the same path but do different things?
  • Which C# / .NET free or standard bits and pieces do I need to make a simple Windows desktop app backed by my database?
  • ReSharper: Can I make my own context action?
  • to avoid page refresh during button click event in asp.net
  • How to deny the move to the next WizardPage in .net?
  • Entity Framework and Modeling Collections with an Interface as a return type
  • shadow
    Privacy Policy - Terms - Contact Us © 35dp-dentalpractice.co.uk