tolist

Difference between “ToListAsync()” and “AsAsyncEnumerable().ToList()”

早过忘川 提交于 2021-01-03 07:10:21
问题 Function need to return Task<List<Record>> Following both options are returning Task<List<Record>> , which one is more efficient? Is there any standard way here? Option 1 : Task<List<Record>> GetRecords() { return DbContext.Set<Record>.Where(predicate).ToListAsync(); } Option 2: Task<List<Record>> GetRecords() { return DbContext.Set<Record>.Where(predicate).AsAsyncEnumerable().ToList(); } 回答1: Go for option 1 ToListAsync as the source code of AsAsyncEnumerable explicitly mentions This is an

mvc4 take value from a tolist query and apply it to another query

爱⌒轻易说出口 提交于 2020-01-07 09:45:52
问题 I basically have (2) .Tolist() queries in my controller; What I would like to do is get a list of numbers from a specific column and embed it into the 2nd .tolist query in the controller, this example should clear it up int myid = Convert.ToInt32(User.Identity.Name); // I would like to get extract the info. from ProfileID column and use in comments tolist var friendprofile = sqlConnection.Query<profile>("Select * from profiles where ProfileID In (Select ProfileID from followings where me=

dataframe values.tolist() datatype

不羁的心 提交于 2020-01-01 07:11:25
问题 I have a dataframe like this: This dataframe has several columns. Two are of type float : price and change , while volme and amount are of type int . I use the method df.values.tolist() change df to list and get the data: datatmp = df.values.tolist() print(datatmp[0]) [20160108150023.0, 11.12, -0.01, 4268.0, 4746460.0, 2.0] The int types in df all change to float types. My question is why do int types change to the float types? How can I get the int data I want? 回答1: You can convert column-by

Pandas DataFrame column to list [duplicate]

百般思念 提交于 2019-12-28 02:21:09
问题 This question already has answers here : How do I convert a pandas Series or index to a Numpy array? (7 answers) get list from pandas dataframe column (7 answers) Closed 9 months ago . I am pulling a subset of data from a column based on conditions in another column being met. I can get the correct values back but it is in pandas.core.frame.DataFrame. How do I convert that to list? import pandas as pd tst = pd.read_csv('C:\\SomeCSV.csv') lookupValue = tst['SomeCol'] == "SomeValue" ID = tst

Why IEnumerable.ToList() return fields in alphabetical order?

旧巷老猫 提交于 2019-12-13 04:41:14
问题 I have this simple function in a class that return IENumerable Colection using LINQ projection: public IEnumerable<Pedidos> Pedidos_Listar(string sComprobante, Clientes MyCliente = null, DateTime? dDesde = null, DateTime? dHasta = null, bool bCumplidos = false) { using (var context = new OhmioEntities()) { return (from Pedidos in context.Pedidos join Clientes in context.Clientes on Pedidos.ID_Cliente equals Clientes.ID_Cliente where Pedidos.ID_Comprobante == sComprobante select Pedidos)

Syntax using LINQ ToList to cast GENERIC list to list of its base type

泄露秘密 提交于 2019-12-11 14:47:33
问题 I've looked at lots of stackoverflow Q&As about ToList and generic constraints, but I haven't found one that explains the "Syntax Error" in the final return below. Why do I have to explicitly Select and cast the elements ("B")? public interface I1 { } public class C2 : I1 { public static List<I1> DowncastListA( List<C2> list ) { // "A": A concrete class works. return list == null ? null : list.ToList<I1>(); } public static List<I1> DowncastListB<T2>( List<T2> list ) where T2 : I1 { // "B":

EntityFramework : Calling ToList() on IQueryable with ~11.000 records takes 10 seconds

浪尽此生 提交于 2019-12-10 10:57:03
问题 I want to return a relatively large number of records from SQL Express 2008 R2 server, via EntityFramework 4 through WCF service to a WCF client. My test table contains around 11.000 records at the moment. The LINQ query is as simple as this: Database DB = new Database(); // create object context var retValue = DB.Entities.Persons .Include("District") .Include("District.City") .Include("District.City.State") .Include("Nationality") return retValue.ToList(); This takes about 10 seconds to

When IQueryable returns no record ToList() throws an exception

江枫思渺然 提交于 2019-12-07 12:39:21
问题 dataContext.Geo_Countries.Where(c => c.Name.Contains(searchKey)).ToList(); when the IQueryable returns no records I get a value null exception. What is the solution? 回答1: I suspect you don't get the problem when there are no matches - I suspect you get it when there's a row in your database with no Name value. Either that, or you're doing something else which you haven't shown us. What does the stack trace look like? 回答2: try to use this code dataContext.Geo_Countries.Where(c => c.Name !=

EntityFramework : Calling ToList() on IQueryable with ~11.000 records takes 10 seconds

我与影子孤独终老i 提交于 2019-12-06 13:46:11
I want to return a relatively large number of records from SQL Express 2008 R2 server, via EntityFramework 4 through WCF service to a WCF client. My test table contains around 11.000 records at the moment. The LINQ query is as simple as this: Database DB = new Database(); // create object context var retValue = DB.Entities.Persons .Include("District") .Include("District.City") .Include("District.City.State") .Include("Nationality") return retValue.ToList(); This takes about 10 seconds to complete. The same SELECT query takes less than 1 second when executed in SQL Server Managament Studio.

Rules of thumb for when to call ToList when returning LINQ results

百般思念 提交于 2019-12-05 16:56:06
问题 I'm looking for rules of thumb for calling ToList/ToArray/MemoizeAll(Rx) on IEnumerables , as opposed to returning the query itself when returning IEnumerable of something. Often I find that it is better to just return the query and let the caller decide whether a list is needed or not, but sometimes it can come back and bite you in the rear due to the lazy nature of linq. I want to collect guidelines such as: Call ToList if: you create new objects (eg. in a select) you have side effects in