w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
Returning results from stored procedure as IEnumerable
Your SqlCommand does not have a corresponding connection. Either use: _command.Connection = conn; or create the SqlCommand by using conn.CreateCommand(...)

Categories : C#

IEnumerable View returning null on HttpPost
Unfortunately you cannot bind in this way. Model binding depends upon how generated html looks like. In this particular case it should look something like: <input id="item_Buy" type="checkbox" value="true" name="item[0].Buy" checked="checked"> If you are okay with some workarounds, you can use a for loop instead of foreach loop where you can add an index to each control name and model binder could bind them properly. There are some really helpful discussions available, you can check here: ASP.NET MVC - Insert or Update view with IEnumerable model. And also Model Binding To A List. Another one is: Modelbinding IEnumerable in ASP.NET MVC POST?

Categories : Asp Net

What is the equivalent F# code of a property returning IEnumerable
The equivalent to C# iterator method in F# is the seq { .. } block. This is an expression, so you can use it to define methods (but also inline sequences). Inside the block, you can use yield (which corresponds to yield return in C#) and you can also use yield! to return all elements of a given sequence. The expression that creates an array object[] can be translated to an object literal [| ... |] but we need to make sure that the values are returned as objects. This can be done either by adding type annotation or by adding explicit boxing using the box function: Your C# code looks like a read-only property which can be translated as just a value declaration using let: let EnumerateFooBar = seq { yield [| box "foo"; box "bar" |] } An alternative using type annotations: let EnumerateF

Categories : F#

IEnumerable is returning Null, Needs to Return Attribute Value
main here is the root element: <Server> - which does not have a Nid attribute. You want something like: Guid nid = (Guid)main.Element("Network").Attribute("Nid"); Or for multiple: Guid[] arr = (from attr in main.DescendentsOrSelf().Attributes("Nid") select (Guid)attr).ToArray();

Categories : C#

weird extension issue with codefirst EF dataset (inconsistenly returning IEnumerable or IQueryable)
The IQueryable.Where<TSource> method takes an Expresssion<Func<TSource, bool>>. Change the where argument in your search method to type Expression<Func<T, bool>> and it will compile without a problem. The reason for your second usage resolving correctly is because of homoiconicity. A lambda expression gets interpreted as either a Func or an Expression<Func>, depending on the context. If the method expects the former, the compiler will look at c => c.ID == id and see a Func<int, bool>; if it expects the latter, it will see an Expression<Func<int, bool>>.

Categories : C#

Convert IEnumerable to IEnumerable without knowing types at compile time
Using the LINQ Select method: var result = listA.Select(a => Converter(a)); Since you are using .NET 4.0, you really should avoid using object and use generics.

Categories : C#

How can I convert IOrderedEnumerable & IEnumerable> & IEnumerable to one common format?
You could always create a generic method and check the type in the method. Something like public void constructHtml<T>(T nodeList){ // Check type T and do something with it }

Categories : C#

Select IEnumerable from IEnumerable> linq
Use SelectMany operator: from q in questions from a in q.AnswerList select a.AnswerBasicViewModel Or simply questions.SelectMany(q => q.AnswerList) .Select(a => a.AnswerBasicViewModel)

Categories : C#

How to convert IEnumerable> to List?
Since lstShuffle implements IEnumerable<string>, you can mentally replace T with string: you're calling IEnumerable<IEnumerable<string>> GetPermutations(IEnumerable<string> items). As Alexi says, SelectMany(x => x) is the easiest way to flatten an IEnumerable<IEnumerable<T>> into an IEnumerable<T>.

Categories : C#

write IEnumerable> to file
use serialization. To write to file var serializer = new JavaScriptSerializer(); File.WriteAllText(filename, serializer.Serialize(points)); and to read from file var points = serializer.Deserialize<List<Point>>(File.ReadAllText(filename));

Categories : C#

Equality between two IEnumerable> objects
SequenceEqual tests using Equals; to use SequenceEquals you'll need to implement it yourself. Try using the Zip operator with sequence equals. // example var first = Enumerable.Range(1, 10).Select(i => Enumerable.Range(1, i)); var second = Enumerable.Range(1, 10).Select(i => Enumerable.Range(1, i)); bool nestedSequencesEqual = // test if each sequence index is equal first.Zip(second, (f, s) => f.SequenceEqual(s)) // ensure all like sequences are equal .All(b => b); // returns true

Categories : C#

Linq Filter IEnumerable against another IEnumerable
This should works: ListB.Where(x=>FilterListA.Any(y=>y==x.ClassA)); It gets all elements from ListB which have equivalent element in FilterListA. If object of ClassA included in element of list is listed in FilterListA it's returned. EDIT: as gunr2171 said you can use Contains ListB.Where(x=>FilterListA.Contains(x.ClassA));

Categories : C#

Cannot convert IQueryable> to return type IEnumerable
It looks like you want to select items from a collection within a collection and flatten the result into a single sequence. Conceptually, something like: If that's the case, you're looking for the SelectMany method: var propertyNames = _dbSis.ModuleKinds .Where(t => t.PerTypeConfigurationId == configurationId) .SelectMany(x => x.PerTypeConfiguration.Properties) .Select(z => z.Name);

Categories : C#

Abraham Twitter API 1.1 Oauth library only returning "null"
Assuming you are running the latest TwitterOAuth code the get line should look like this. $tweets = $connection->get( "statuses/user_timeline", array("screen_name" => $twitteruser, "count" => $notweets) );

Categories : PHP

Javascript library (tabSlideOut) hosted on GoogleCode returning 403 error
It seems working at my end as well. You may track the URL requested using firebug. or Please provide the URL of webpage in which you are accessing JS file because sometimes cross site scripting is the reason. Thanks, Krishan

Categories : Javascript

IEnumerable to Dictionary>
As the relation is one to many, you can use a lookup instead of a dictionary: var lookup = words.ToLookup(word => word[0]); loopkup['s'] -> store, separate... as an IEnumerable<string> And if you want to display the key/values sorted by first char: for (var sortedEntry in lookup.OrderBy(entry => entry.Key)) { Console.WriteLine(string.Format("First letter: {0}", sortedEntry.Key); foreach (string word in sortedEntry) { Console.WriteLine(word); } }

Categories : C#

Python mock library not returning correct mock object for 'patch'
import logging from mock import Mock, patch my_mock = Mock() my_mock.id = 'i-12341234' with patch('logging.PlaceHolder', new=my_mock) as mockobj: mockobj.return_value = mockobj # <-- added this line. print mockobj.id newobj = logging.PlaceHolder(None) print newobj.id Alternative import logging from mock import Mock, patch my_mock = Mock() my_mock.id = 'i-12341234' my_mock.return_value = my_mock # <--- with patch('logging.PlaceHolder', new=my_mock) as mockobj: assert mockobj.id == 'i-12341234' newobj = logging.PlaceHolder(None) assert newobj.id == 'i-12341234'

Categories : Python

TreeView: Cannot convert from 'System.Collections.Generic.IEnumerable' to 'System.Collections.Generic.IEnumerable
Because a LINQ query returns some IEnumerable<T>, not a List<T>, so you have to apply ToList: BuildTree( //create child from the propertyPath (from propertyPathElement in pathElementGroup where propertyPathElement.path.Length > pathElementGroup.Key.Length + 1 select propertyPathElement.path.Substring(pathElementGroup.Key.Length + 1)).ToList()) }

Categories : C#

Why is converting 'System.Collections.Generic.IEnumerable' to System.Collections.Generic.IEnumerable is considered an error
Due to the way generics are implemented in Java, you can use a generic type like List<E> without giving the generic arguments (e.g. just List). C# does not work this way, so the type you gave in the title of this question (System.Collections.Generic.IEnumerable) doesn't actually exist. The actual question here is: Why is converting System.Collections.Generic.IEnumerable<System.Collections.Generic.IEnumerable<TMS.Models.SDUser>> to System.Collections.Generic.IEnumerable<TMS.Models.SDUser> considered an error. The answer is similar to the reason you can't assign an object of type int[,] to a variable of type int[]. Perhaps you meant to use SelectMany instead of Select on the line that is reporting the error. This "flattens" the individual results to produce a si

Categories : Entity Framework

Qt: mingw compiled library does only work with both library.so and library.lib file present
That's weird, I think you should get a *.a and *.dll files when building a shared lib with MinGW on Windows, as said in the documentation: In windows, MinGW will output .a and .dll, MSVC2010 will ouput .lib and .dll. In linux, MinGW will output .so, .so.1, .so.1.0 and .so.1.0.0 – .lib, .a and .so are import libraries. You definitely shouldn't rename your file! Be careful to: not to include the "lib" prefix after "-l" in your project file. put everything after after "-l" in lower case as you're on Windows not adding any extension to your library name after "-l" add and reference the .h file used in your library A real example using QtWebsocket lib: INCLUDEPATH += "$${PWD}/include/" LIBS += -L"$${PWD}/libs/" -lqtwebsocket ... HEADERS += ... $${PWD}/include/QWsSocket.

Categories : Qt

How to make my JAR library to be included in the in AndroidManifest.xml and use it as a shared library
<uses-library> is for libraries that are part of device firmware (SDK add-ons). So, unless you are distributing your own hardware or ROM mods, <uses-library> will not be of use to you. Moreover, generally speaking, you want to have independent copies of that library, one per app using it. That way, you can update each app separately. Otherwise, changes to your JAR may necessitate simultaneous changes to all of your apps, and since you are not in charge of installing those app updates (users are), that could be a major problem.

Categories : Android

Nested IEnumerable<> in C#
Yes, that is the only way it would work. Each value should be returned using the 'yield return', you cannot return values as group of collection. This is wrong static IEnumerable<string> EnumerateA() { yield return "1"; yield return EnumerateB("2"); yield return EnumerateB("3"); } Correct way would be static IEnumerable<string> EnumerateA() { yield return "1"; foreach (var str in EnumerateB("2")) { yield return str; } foreach (var str in EnumerateB("3")) { yield return str; } }

Categories : C#

When to use IEnumerable vs IObservable?
IObersvable is a specialized class that can be used for pub/sub and various other patterns. You would know when you needed to return an observable, so if there is not specific need then return IEnumerable. Update to question in comment Basically, IObervable<> uses a "Push" mechanism adn IEnumerable<> uses a "Pull" mechanism. If you are going to simply obtain a list of data that doesn't need to notify subscribers of changes (push) then you can use IEnumerable. If a subscriber (Window, Control, other Client programs/routines, etc...) needs to know when data changed then use IObservable<>. One example is using IObservable to update the main UI thread in a windows program from a child thread (Normally this cannot be done without fancy footwork. Read up on .net Reactive Extensions

Categories : C#

Difference between var and IEnumerable in C#?
var is a contextual keyword that implicitly types a variable. When you use IEnumerable<T> you are explicitly stating the type to be defined, were as var will use type inference. It doesn't really make a difference which one you use, more of a coding style IMO, I personally use var when returning something from a collection using LINQ rather than IEnumerable<T> or IQueryable<T>. var value5 = list.Where(i => i == 5).ToList(); IEnumerable<int> value5 = list.Where(i => i == 5).ToList(); Both will generate the same output. With regards to point 3 and 4. I don't believe that IEnumerable is any more beneficial for in memory collections at all. Behind the scenes the CLR will infer the variables type (When using var) at runtime, most likely to IEnumerable<T&

Categories : C#

IEnumerable - Move Next
Well you could store an IEnumerator<T> instead, and change GetNextQuestion to: return _exam.MoveNext() ? _exam.Current : null; However, at that point you're not actually adding any value with the Exam or WizardStepService classes, and you might as well just use IEnumerator<T> directly in Main. Note that your Main method itself is a little odd - it has repeated code where a foreach loop would be simpler - and you're unconditionally asking three questions. Note that if you have a type with an IEnumerator<T> as a field, you probably want to implement IDisposable in order to dispose of the iterator, too - it all gets a bit messy.

Categories : C#

Streaming an IEnumerable
The TextReader Class exposes multiple methods to read data. If you pass an instance to some external code, it may use any of the methods, not just the ReadLine Method. The methods that you need to override at a minimum are the Read Method and the Peek Method. If you don't override them, they both always returns -1, indicating that the end has been reached. All other methods, including the ReadLine Method, provide default implementations based the Read Method. You can override them (for example, for improved performance), but you are not required to. From MSDN: Notes to Inheritors A derived class must minimally implement the Peek and Read methods to make a useful instance of TextReader. So your implementation does not work as is.

Categories : C#

Why use readonly IEnumerable
The readonly keyword here applies to the field _orders. It simply means that the field can not be assigned a different value during the lifetime of the object. For example, this is not possible: class OrderHandler { private readonly IEnumerable<Order> _orders; public OrderHandler() { // Set orders. } void SomeMethod() { _orders = new Order[0]; } } You will receive this compiler error: A readonly field cannot be assigned to (except in a constructor or a variable initializer) This does not make the collection read-only. For example, you could still do this: class OrderHandler { public readonly IEnumerable<Order> Orders; public OrderHandler() { Orders = new List<Order>(); } } ((List<Order>

Categories : C#

Oracle Query is returning value when setting value to it, but not returning value when passing date value
Since you're already forcing the date format, you can use the following query instead: SELECT INCIDENT_ID FROM INC_SM1 I WHERE I.CLOSE_TIME >= START_DATE AND I.CLOSE_TIME < END_DATE

Categories : Oracle

Python - Chaining methods: returning `self` vs returning a new cloned object
Django does this so that the base query can be kept around and reused, without inheriting changes from a future "child" query, like your exclude() on your filter(). I'm guessing somebody tried storing queries for later, and realized that didn't work well without copying. I cloned the django repo and did a quick git log on django/db/models/query.py, searching for the phrase clone. The patch that introduces this change is here: https://github.com/django/django/commit/d4a3a4b

Categories : Python

Is there a way of converting a T to a IEnumerable without using Add or AddRange
IEnumerable<Node> list = new[] { item }; A single element array? Equivalent to: IEnumerable<Node> list = new Node[] { item };

Categories : C#

Setting IEnumerable KeyValuePair
Could you try something like the following: foreach (var tree in newTrees) { var keyValuePair = _myObject.Trees.Where(s => s.Key == tree.Key).First(); keyValuePair = new KeyValuePair<Tree, int>(tree.Key, tree.Value); } Now you are looping only the newTrees and the Where(...) finds the corresponding element(s) in _myObject.Trees without explicitly looping. Note that the call to First() assumes that any key in newTrees already exists in _myObject.Trees and that it exists only once. I hope it helps!

Categories : C#

LINQ IEnumerable OrderBy
One of the possible ways to use reflection public static IEnumerable<T> Sort<T>(this IEnumerable<T> list, string column, SortDirection direction = SortDirection.Ascending) { Func<T, object> selector = p => p.GetType().GetProperty(column).GetValue(p, null); return (direction == SortDirection.Ascending ? list.OrderBy(selector) : list.OrderByDescending(selector) ); }

Categories : C#

Is IEnumerable.Last() optimized for List?
You are right, if you take a look the code how to implement Last (from Reflector): public static TSource Last<TSource>(this IEnumerable<TSource> source) { if (source == null) { throw Error.ArgumentNull("source"); } IList<TSource> list = source as IList<TSource>; if (list != null) { int count = list.Count; if (count > 0) { return list[count - 1]; } } else { using (IEnumerator<TSource> enumerator = source.GetEnumerator()) { if (enumerator.MoveNext()) { TSource current; do { current = enumerator.Current; } while (enumerator.MoveNext())

Categories : C#

WCF IEnumerable - Streamed Transport Net Tcp
Here is guidance on transferring large data with streaming. http://msdn.microsoft.com/en-us/library/ms733742.aspx At the bottom of the page is a link to some samples, one of which shows using TCP. http://msdn.microsoft.com/en-us/library/ms789010.aspx If this doesn't help, then perhaps you could provide more detail on how it is failing (error message)?

Categories : Wcf

Why is IEnumerable faster than IQueryable?
I don't know what _db.Memos returns but in test 2 Dim iEnum As IEnumerable(Of Memo) = _db.Memos.AsEnumerable all the records may be loaded into memory there and then. In test 3 the records are loaded when you call ToList: iQuer.Where(Function(f) f.Active).ToList() You should do 2 things: Move your stopwatch lines before the assignment and compare results then . Setup a trace in your db to see where the code actually hits the database.

Categories : Dotnet

IListSource or IEnumerable error
You need to bind your repeater against an object which implements the IListSource or IEnumerable interface, the SqlCommand class does not meet that qualification; however a DataSet does. So try this: protected void Page_Load(object sender, EventArgs e) { int newsDate = -7; using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["IGSConnectionString1"].ConnectionString)) { using (SqlCommand cmd = new SqlCommand("SELECT * FROM igs_news WHERE DATE(newsDate) = DATEDIFF(day,@newsDays)", conn)) { cmd.Parameters.AddWithValue("@newsDate", newsDate); SqlDataAdapter da = new SqlDataAdapter(); da.SelectCommand = cmd; DataSet ds = new DataSet(); conn.Open(); da.Fill(ds)

Categories : C#

How to loop this object without IEnumerable
Try removing your foreach and have: for (int x = 0; x < results.Count; x++ ) //typecast x a get error to loop the results { TableRow tr = new TableRow(); Table1.Rows.Add(tr); GetErrors value = results[x]; TableCell tc = new TableCell(); tc.Text = results[x].FWWDIR_ROW + results[x].FWWDIR_ERR_INVOICE + results[x].FWWDIR_ERR_ACCOUNT; tr.Cells.Add(tc);// = new TableCell(); } Is appears you are trying to use a class like a method and therefore the fields like an array of strings. Each item in "results" is an instance of the GetErrors class and you cannot use it in a foreach unless you implement IEnumerable and have the GetEnumerator return the values in each of the fields.

Categories : C#

Most efficent way to work with IEnumerable
The loops, as written, are likely one of the fastest options. Since this is all in memory, and each write operation appears to be on a separate instance (no synchronization), you could potentially parallelize this to get some gains: Parallel.ForEach(this.AllParameters, par => { foreach (Parameter subPar in par.WrappedSubParameters) { subPar.IsSelected = false; } par.IsSelected = false; }); Note that I'm only parallelizing the outer loop (on purpose), as this should provide enough work items to adequately use all processing cores. Another potential issue - if your IsSelected properties are bound to a control via Data binding, your UI will potentially be updating continually, which could explain the very slow update times. This would cause parallelization t

Categories : C#

IEnumerable property without type
You need to use the non-generic type System.Collections.IEnumerable. (note the different namespace) Note that in .Net 4.0+, you can use IEnumerable<object> instead (due to covariance).

Categories : C#

Does ienumerable from yielding can ever be null?
No. The C# compiler converts your iterator block into an iterator instance, which is what is returned from your method. This can never be null. That said, it is of course possible to yield null values within your enumeration, provided that the generic type of your enumerable is a reference type or a nullable type.

Categories : C#



© Copyright 2017 w3hello.com Publishing Limited. All rights reserved.