C# - Is Returning List<T> From Method Differ In Performance From Returning Collection<T>?
Jul 18, 2010
We have a web project that contain its business methods in a class library project called "Bll.dll"
some methods of Bll.dll return List<> ... from a source - that i don't remember now - told that returning Collection<> is better than returning List<> Is it a valid ? Note that i don't make any process on values returned from BLL methods .. just view it in a web page
I'm using a web service and I want to return a list to my client. I am nearly newby at web services and I can't return a List<String> object to my client. But when i call the method it says "Unable to cast object of type 'System.Collections.Generic.List`1[System.String]' to type 'System.String[]'" What should I do?
How is it possible to return some kind of list from a WCF service, this the method in my WCF service.
My interface:
[OperationContract] [WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped, UriTemplate = "Locations")] IList<Location> GetLocations(); public IList<Location> GetLocations() { Pazar.Data.Repositories.LocationRepository locRepository = new Pazar.Data.Repositories.LocationRepository(); return locRepository.GetRootLocations().ToList<Location>(); } and this how my GetRootLocations looks like, It returns IQueryable, I wonder if I can maybe return IQueryable from my WCF service? public IQueryable<Location> GetRootLocations() { IQueryable<Location> locations = GetAll().Where(p => !p.ID_Parent.HasValue).OrderBy(p => p.Sequence); return locations; }
Would it be better in terms of payload, if I return a datatable as a List<DataRow> from a WCF method? I have WsHtppBinding for my WCF. I am expecting the datatable to contain 5,000 to 10,000 records.
Also, how can I test the difference in payload sizes when returning a DataTable Vs List<DataRow>?
function populateDDL(ddl_id) { var option_str = ""; var x; for(x in datalist){ option_str += " <asp:ListItem Value='" + datalist[x] + "' Text='" + datalist[x] + "'></asp:ListItem>" } var country_div = document.getElementById(ddl_id); country_div.innerHTML = option_str; }
This is sure the datalist is not empty and also Dropdown list populated perfectly..but dnt know why after clicking on my page add button I am not getting the selected value.
I'm having troubles remembering how to grab the list view's state, or page, so that when you leave the list, you can return to the list view page you left on. I have a data pager, and I have hyplerlinks for items in the list view that take you to a file upload or file delete page, and then returns to the list view. It returns to the list view's initial state (first page).
I have a page where users can search by company name, the data list is pulled from an Excel spreadsheet hosted on the site. I'm seeing some strange results returned, for example:
In the company field say there are the following entries:
Anns Company Bernards Business Company B Dermots Domain Property Company
If I search for "Com" I get the following returns (correct):
Anns Company Company B Property Company
If I search for "Der" I get my "Sorry there are no matching results" message (Incorrect)
If I search for "Ann" I get the following returns (Correct):
Anns Company
And if I search for "e" I get the following returns (Correct):
Bernards Business Dermots Domain Property Company
It seems random as to why it doesn't return some values, I've tried moving rows around to see if that's the problem but it makes no difference. My range is set correctly in the spreadsheet.
When I debug the VB code behind, when I search for something that works correctly e.g. "Com" in the above example, once enter the value and click search Visual Studio begins steping into the code and shows me the contents of the variables however when I search for something that's not working e.g. "Der" and click search it immediatly returns the "Sorry there are no matching results" message and the code behind does not get steped into.
I have a simple asp.net form that has a textbox that collects phonenumbers to send SMS messages. If I bypass the form and hardcode the numbers using the following format:
"2133211234",#1233211234"
the code works fine. However when i try to use this same format using my form, the sms will ONLY send to the first number. I have a feeling i'm missing out on some property on my form that will accept all of the values. how how i can add some lines of code that will allow users to enter numbers like this:
3123211234,4123212344 and have it converted to the format above when the number is submitted?
I have a function inside a utility class which returns the current session User ID. It throws object reference not set to instance of object ? How do I check it for null & remove this error ?
public static string GetSessionUserID { get { string userID = ""; if (System.Web.HttpContext.Current.Session["userID"].ToString() != null) { userID = System.Web.HttpContext.Current.Session["userID"].ToString(); } if (userID == null) { throw new ApplicationException("UserID is null"); } else return userID; } }
I have created alot of stored procedures in my application that return the result of a query in a datatable object. I never use a dataset. Why would I ever use a dataset over simply returning the result of a query as a datatable object?
I have a problem with getting jquery to retrieve results from a WCF service. I am hosting the WCF service within IIS and when I attach the debugger to this process I can see that the code is processed successfully. However, when it hits the callback within jquery there is no data??
I have set up a trace on the wcf service and there are no errors. It just seems as though the data is lost after the wcf service method completes.
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)] public class EcopsService : IEcopsServiceContract { #region IEcopsServiceContract Members public string Echo(string echoThis) { return string.Format("You sent this '{0}'.", echoThis); } #endregion }
My SQL query joins on multiple tables, and because of this it is displaying multiple results. I know about SELECT DISTINCT, but one of the fields ('Account.Name') is occasionally different, so it treats this record as a new row. Here is my SQL:
I have a call to a function in my business logic area. It should be returning a true.
[URL]
This url above is the culprit. The code doesn't seem to like the .asp type of file. I wonder why this is the case. I get a true response for a html or php type of file. The above returns false. Does anyone know why?
[Code]....
[Code]....
Public Shared Function MakeURL(ByVal url As String) As String Return "http://" & url.Replace("http://", "") End Function
I'm saving military time into the database. Then I need to pull this data back out of the database. To get just the time without the date I can do this: String.Format("{0:T}", pullsaved.First.timeValue) But this returns a six digit time, e.g. 100000 (HHmmss). But I want it to return just HHmm (1000). I tried the following, but it didn't work. DateTime.ParseExact(String.Format("{0:T}", pullsaved.First.timeValue), "HHmm", CultureInfo.InvariantCulture)
I need to call a popup page with terms and conditions (modal if possible), and once the user ticks the acceptance tick box in T&C popup and closes popup page I need to get the tick box value back into the calling page. How can achieve this via code?
I am having an issue getting a value from a ModalDialog back to the page that called it so I can change the alternate text of an image based on what is entered in the textbox.Any thoughts on how to properly return the value and use it?Provided below is my code related to this.Main Page (This is a Content Page!) on PageLoad
I have an asp.net web application that use FormsAuthentication. Now, the application has a WCF Service that need to use Basic Authentication. So, I need to return the 401 status code, but everytime it's picked up by asp.net and redirecting me to the login page.How could I disable this feature and finally being able to throw a 401 without intervention from the FormsAuthentication module?
I would like to return an function in some JSON. How can I stop my function being output as text (how can i stop it being wrapped in quotation marks?).
eg: [Code]....
In script the value of name is just a string. Is there some object I can set name to that will wrap my script and emit as script not a string?I want to do this to better control the "remote" rule of jQuery validate. I have my own dataannotationmodelvalidator for it and its doing this atm:
[Code]....
Which is working fine for the most part except I can't get the value of 'name' to be a function. It comes out as a string. Alternatively is there someway to control what JSON serializer this thing is using alternatively. We need a wrapper function so you can do something like:
name = Emit("function(){ return $(this).val(); }")