w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
MVC Cannot convert lambda expression to type because it is not a delegate
Found what happens. The asp.net tags are not allowed in the SetContent() that way. The correct way to do it is: CBsettings.SetContent(() => { ViewContext.Writer.Write("<h1>Hello World</h1>"); ... }); So sad the intellisense doesn't give a clue about what is wrong.

Categories : C#

Cannot convert lambda expression to delegate type
I think you just have your syntax off a bit. Try: public user GetUser(int intUserID) { using (var context = new iomniEntities()) { user u = context.users.Where(u => u.userID == intUserID).FirstOrDefault(); return u; } } Or to hold onto your version, it just needs touched up: public user GetUser(int intUserID) { using (var context = new iomniEntities()) { user u = context.users.FirstOrDefault(user => user.userID == intUserID); return u; } }

Categories : SQL

Webgrid: Cannot convert lambda expression to type 'object' because it is not a delegate type
You can't use embedded razor strings within the lambda expression, as @Alessandro D'Andra suggests you have to use x => "<img src='" + someString + "'></img>"; instead. You might also have to wrap it all in an MvcHtmlString to prevent Razor from escaping the string once it is used by the formatter, but I don't know exactly how the formatter works - you have to try it. I made a small test file to find out exactly what the Razor compiler would do with your code. This is the razor file: @{ string someString = "somestring"; Func<object, object> a = x => "<text><img src='" + someString + "'></img></text>"; Func<object, object> b = x => @<text><img src="@someString"></img></text>); } The ASP.NET

Categories : C#

WPF: Cannot convert lambda expression to type 'string' because it is not a delegate type
Your NotifyPropertyChanged expects a string, and you're passing it a delegate. Try: public string SelectedTransactionName { set { if (_selectedTransactionWsName == value) return; this._selectedTransactionWsName = value; // InitializaMessageElement(value.WsMethodName, transactionTypes); InitializaMessageElement(); this.NotifyPropertyChanged("SelectedTransactionName"); this.NotifyPropertyChanged("IsTransactionNameSelected"); } get { return this._selectedTransactionWsName; } }

Categories : Wpf

Convert async lambda expression to delegate type System.Func?
No can do. When someone expects a Func<T> f you can assume it will be invoked with something like result = f() - i.e., it does not know about async behavior. If you cheat it by using .Result like you have - it will deadlock on UI thread because it wants to schedule the code after await (in _Fetch) on the UI thread, but you have already blocked it with .Result. Async lambda can be passed to Action since it has no return value - or to Func<Task> or Func<Task<T>>. Looking at your case, the GetOrCreateObject appears to be calling GetOrFetchObject. One of the GetOrFetchObject overloads accepts a Func<Task<T>>. You can try calling that method with your async lambda and see if it helps.

Categories : C#

How to use a lambda expression on an ExpandoObject C# to find an array element value?
I assume gifts is of the type List<Gift[]>. Then you would do: var test = ((List<Gift[]>)Model.moduleData.gifts).FirstOrDefault(item => item[index][0] == 99); The reason is that the type of gifts is not known at compile time, so the C# compiler has no way of resolving the type of lambda that's being specified.

Categories : C#

LinqPad Error: Lambda expression cannot be converted to 'String' because 'String' is not a delegate type
The problem appears to be that one or more of the properties of object "p" is not a string. However, you most likely are misunderstanding what .Include does. It eager-loads whichever related tables you specify. So if you had: Dim projects = From p In db.Projects.Include("Managers") it would eager-load all of the related records from your "Managers" table for each row in your "Projects" table when the query is executed. Somehow, I don't think this is what you are trying to accomplish with the code you posted.

Categories : Vb.Net

Convert lambda to custom delegate
It's interesting that you say that you had no such issues in a different VS2010 project. It would be good to see what that code (which works) looks like. Are both the source project and the consuming project set to target the same .Net Framework version and possibly also using the same Tools version? Maybe the compiler is having trouble inferring the types - try making the lambda parameters explicitly typed, and/or explicitly casting the lambda to the delegate type: Instruction<string, bool> instruction = (CancellationToken cancellationToken, Action reportProgress, string argument) => SomeOperation(argument); Instruction<string, bool> instruction = (Instruction<string, bool>)((CancellationToken cancellationToken, Action reportProgress, string argument) => SomeOp

Categories : C#

Argument type 'lambda expression' is not assignable to parameter type 'System.Action'
I doubt this has anything to do with mvvmcross or mvvm A quick search for this error message suggests this is more likely to be down to tooling - especially r# - eg see hits like: http://devnet.jetbrains.com/thread/292248 http://caliburn.codeplex.com/discussions/212685 http://youtrack.jetbrains.com/issue/RSRP-178647?projectKey=RSRP If you are running any extensions like r# and you remove or disable them, then this may remove the warning. If disabling them helps, then I would recommend asking the extension vendor(s) for support. If disabling them does not help, then I would recommend investigating the differences between the two projects where the problem does/doesn't occur - that will hopefully yield the answer.

Categories : C#

Convert sql to Lambda expression
Here is how you can do it var galleryIds = (bidModelses.Where(b => b.UserId == [YOURPARAMETER]) .Select(b => b.GalleryId)); var query = (bidModelses.Where(bm => galleryIds.Contains(bm.GalleryId)) .GroupBy(bm => bm.GalleryId) .Select(gbm => new {gbm.Key, MaxBid = gbm.Max(p => p.BidId)}));

Categories : SQL

Cannot convert type 'DelegateType' to 'System.Delegate'
Indeed, you cannot specify a : Delegate constraint - it simply cannot be done (the compiler stops you). You might find it useful to add a where DelegateType : class, just to stop usage with int etc, but you can't do this all through generics. You will need to cast via object instead: (Delegate)(object)d However, personally I think you should be storing DelegateType, not Delegate, i.e. protected class PrioritizedDelegate : IComparable { public DelegateType d; public int priority; public PrioritizedDelegate(DelegateType d, int priority) { this.d = d; this.priority = priority; } } Note I removed the <DelegateType> from the above: because it is nested inside a generic type (PrioritizedEvent<DelegateType>) it already inherits this from the

Categories : C#

Show list of all Enums of type except the one passed via lambda
I don't think you have the model object, as-is. You could add it as another parameter: @Html.RadioButtonForEnum(Model, model => model.Status) public static MvcHtmlString RadioButtonForEnum<TModel, TProperty>(this HtmlHelper<TModel> htmlHelper, TModel model, Expression<Func<TModel, TProperty>> expression) { string currentStatusName = expression.Compile()(model).ToString(); ...

Categories : C#

Querying and converting data using a lambda expression
Not entirely sure I understand what you're after, but if you're looking to create a single function that returns a list of entities based on some filtering criteria, I typically do the following. First, I create a filtering object that contains all possible criteria I could filter on: public class SysLogFilter { public string Attribute1 {get;set;} public string Attribute2 {get;set;} public DateTime Date {get;set;} } Then, you pass this filter to your method and alter your query accordingly: public List<SysLog> List(SysLogFilter filter) { Entities dbContext = DAODbContext.Instance.EntitiesFactory(); IQueryable<SYSLOG> query = dbContext.SYSLOG; if(!String.IsNullOrWhitespace(filter.Attribute1)) query.Where(s => s.Attribute1 == filter.Attr

Categories : C#

Pass lambda expression to lambda argument c++11
Try using std::function: #include <functional> int main() { int x=0; int y=0; auto f = [x,y](std::function<double(int)> func) -> double {func(0); return 0.0;}; f([x](int i) -> double {return 0.0;}); }

Categories : C++

Difference between lambda expression and expression lambda
Yes there is - or I should probably say that one defines the other. A lambda expression allows you to assign simple anonymous functions. An expression lambda is a type of lambda that has an expression to the right of the lambda operator. The other type of lambda expression is a statement lambda because it contains a statement block {...} to the right side of the expression. Expression lambda takes the form: number => (number % 2 == 0) Statement lambda takes the form: number => { return number > 5 }

Categories : C#

Expression.Convert using type that isn't included
AS DAL.Foo is closer(in current assembly) than DTO.Foo (in an included assembly) hence the compiler picks it up first. It is expected and consistent behaviour, not a bug. You need to specify the name explicitly so, change this x => ((Foo)x).Bar, to x => ((DTO.Foo)x).Bar,

Categories : C#

Delegate types and covariance with a generic delegate type
The problem is the two delegate types simply aren't compatible. In order to make this work you are going to need to add an indirection layer which converts the arguments between ICommand and TCommand. public void RegisterHandler<TCommand>(CommandHandler<TCommand> handler) where TCommand : ICommand { mCommandHandlers.Add( typeof(TCommand), (command) => handler((TCommand)command); ); }

Categories : C#

Error when using a Linq Expression variable instead of lambda expression directly
Compile your expression into executable code (delegate): var types = assembly.GetTypes().AsEnumerable().Where(_standardFilter.Compile()); As @Kirk stated, it's better not to use expression tree, if you are not going to analyze it. Simply use filter of type Func<Type, bool>.

Categories : C#

Cannot convert expression type error in generic method
If you really need to have the same MouseDown handler for both UserControls, you may write it like this: private void OnRightMouseDown(object sender, MouseButtonEventArgs e) { var uc01 = sender as UserControl01; if (uc01 != null) { uc01.ViewModel.IsSelected = true; return; } var uc02 = sender as UserControl02; if (uc02 != null) { uc02.ViewModel.IsSelected = true; } } Anyway, the better solution would be to have two handlers: private void UserControl01_RightMouseDown(object sender, MouseButtonEventArgs e) { ((UserControl01)sender).ViewModel.IsSelected = true; } private void UserControl02_RightMouseDown(object sender, MouseButtonEventArgs e) { ((UserControl02)sender).ViewModel.IsSelected = true; }

Categories : C#

How can I determine if a delegate is an anonymous lambda?
Basically, you can't. At run-time anonymous lambda's are methods. You could check the method name: static int Foo() { return 0; } void Main() { Func<int> foo = Foo; Func<int> bar = () => 0; Console.WriteLine(foo.Method.Name); // Foo Console.WriteLine(bar.Method.Name); // <Main>b__0 } That's a pretty bad approach, but it may be the only way since foo and bar are otherwise indistinguishable.

Categories : Dotnet

Cannot convert HomeScreen expression to type MonoTouch.UIKit.UIViewController
I asked around on the Xamarin forums aswell and they suggested me to retry to delete the ViewController and remake it because likely the cause is that it didn't create a .h file. After doing that, I launched the debugger using the simulator and now it works. The cause was that it didn't create a .h file when I opened the .xib file in Xcode. The solution was given me here For anyone else that comes across this issue, I hope this helps for you aswell.

Categories : C#

Is there a use for a delegate type that returns a delegate of the same type as itself?
I have an example of some similar code that isn't exactly a recursive delegate, but it comes close. A "Y-Combinator" comes close - and quite frankly I have no idea how it works in practice, but it is used to define recursive functions. Here's the funky code you need to define: public delegate T S<T>(S<T> s); public static T U<T>(S<T> s) { return s(s); } public static Func<A, Z> Y<A, Z>(Func<Func<A, Z>, Func<A, Z>> f) { return U<Func<A, Z>>(r => a => f(U(r))(a)); } Now you can define recursive functions in one line. Factorial: var fact = Y<int, int>(_ => x => x == 0 ? 1 : x * _(x - 1)); var fact5 = fact(5); // == 120 var fact6 = fact(6); // == 720 var fact7 = fact(7); // == 5040 Fibonacci:

Categories : C#

Regular Expression to match C data type
Try: [a-zA-Z]+(([])+|(*)+)? The | operator means "OR." Then the + operator means "one or more of the previous." Therefore, the regex means "some letters, then optionally (one or more []s) OR (one or more *s)." Here is a JSFiddle.

Categories : Regex

Data Type Mismatch in Criteria Expression
Which DB are you connecting to? Assuming it's Access, date literals have to be surrounded by # character, not a single quote e.g #7/12/2013# But a better solution would be to use parametrized query - this way you won't have to worry about proper quotes and simple pass the values as they are. Bonus: that will help to avoid possible SQL injection.

Categories : Vba

Char data type arithmetic expression
On your system, char is signed. It is also eight bits, so 0x80 overflows what a signed 8-bit integer can represent. The resulting value is -128. Since P is some positive value, it is greater than -128. C permits the char type to be signed or unsigned. This is a special (annoying) property, unlike other integer types such as int. It is often advisable to explicitly declare character types with unsigned char so that the behavior is more determined rather than implementation-dependent.

Categories : C

knockout data-bind expression to show string if value not defined
As noted in other SO posts, you can use $data to check if data exists <span data-bind="text: !$data.setup ? '-' : $data.setup"></span> If there is no text then this would evaluate to false, and show the - else show setup. One note is that if you simply did $data.setup it is not a logical test, but adding the ! to the beginning turns it into one for evaluation purposes. http://jsfiddle.net/NGNhD/1/

Categories : Knockout Js

Lambda Expression with Inner Lambda Expression
typeof only applies to type names. If you need the run-time type of c, you must use Object.GetType and say c.GetType(). So, the compiler sees typeof(c) and knows that typeof only accepts type names and is therefore trying valiantly to find a type named c somewhere, anywhere but, alas, it can't. So, it's telling you "I can't find the type c."

Categories : C#

Access Data Type Mismatch in Criteria Expression
The ? parameter placeholders are processed in the order in which they appear, so the this query would be expecting parameter 1 to be WorkDate and parameter 2 to be ProjectID If this is still not working, try wrapping the ? parameter markers in CDate() and/or (presumably) CInt() to force the parameters to the correct datatype(s).

Categories : C#

How to write a VB.Net Lambda expression
The lambda syntax isn't that much different than creating a regular delegate. If creating a lambda which has a return value, use Function. Otherwise if you're creating one that doesn't, use Sub. Dim _new = orders.Select(Function(x) x.Items > 0) Dim action As Action(Of Item) = Sub(x) Console.WriteLine(x.Items)

Categories : Linq

How to read this lambda expression
this function n => n % 2 == 1 takes one argument (n) and return boolean value: true, if n is odd: n % 2 == 1 (n is odd if and only if it has remainder 1 when divided by 2) false otherwise (if n is even) When re-written as ordinary function it would be equivalent to Boolean IsOdd(int n) { -- <- I've named it "IsOdd" since lambda functions have no explict names while ordinary functions have return n % 2 == 1; } Your code below List<int> oddNumbers = numbers.where(n => n % 2 == 1).ToList(); i's a LINQ expression which selects odd values from the list

Categories : C#

How to resolve Lambda Expression
OK, I think this works: NServiceBus.SetLoggingLibrary.Log4Net((Action)(() => MyConfiguration.ConfigureLog4Net("myLog"))); or NServiceBus.SetLoggingLibrary.Log4Net(new Action(() => MyConfiguration.ConfigureLog4Net("myLog")));

Categories : C#

Translating to lambda expression
This is the exact translation. I have no idea why you need the OrderBy tho, considering you are not using the elements in the Select var methods = typeof(double).GetMethods() .OrderBy(x=>x.Name) .GroupBy(x=>x.Name) .Select(x=> new { MethodName = x.Key, NumberOfOverloads = x.Count()}); The same result is obtained by var methods = typeof(double).GetMethods() .GroupBy(x=>x.Name) .Select(x=> new { MethodName = x.Key, NumberOfOverloads = x.Count()}); and you save some computational time since you don't have to order the collection.

Categories : C#

Passing expression into lambda
The approach using Reflection: var result = myList.Where(obj => obj.GetType() .GetProperty("Text1") .GetValue(obj) .Equals("SomeString")); With this way you can change from "Text1" to "Text2" property. Another approach you can use dynamic linq: var result = myList.AsQueryable().Where("Text1=@0", "SomeString"); Dynamic LINQ is also available via nuget.

Categories : C#

c# my sql statement to lambda expression
try below var result = question.GroupBy(x=>new{x.QuestionNo , x.ActivityID}) .Select(g=> new {QuestionNo= g.Key.QuestionNo, ActivityID= g.Key.ActivityID, joined = string.Join(" ", g.Select(i=>i.Question+ "[" + i.Answer +"]"))}) .Take(30); If you want to return this from method you can create new class like below public class Question { public int QuestionNo {get;set;} //change the type accordingly public string ActivityID {get;set;} //change the type accordingly public string joined {get;set;} //change the type accordingly } and change the method to : public IList<Question> GetList() { IList<Question> lstRecords = context.questions.GroupBy(x => new { x.QuestionNo, x.ActivityID }) .Select(g =>

Categories : C#

oledb exception Data type mismatch in criteria expression.
Instead of trying to force the database to understand your string formatting of a date, you should try to use parameterized query and let the framework to figure out what is the correct way to pass a Date to your database Private Sub copyLatestNewstoNewsAndTemporary() Dim SQL2 = "insert into TemporaryNews(Title) " & _ "SELECT Title FROM News where News.news_Date >= ?" Using Con1 = DB_Manager.getConnection() Using objCmd2 As OleDbCommand = New OleDbCommand(SQL2, Con1) Con1.Open() Dim LastDateTimeOfRawNews = new DateTime(2013, 6,7, 16,36,46) objCmd2.Parameters.AddWithValue("@p1", LastDateTimeOfRawNews) objCmd2.ExecuteNonQuery() End Using End Using End Function Parameterized query avoid problems with formatting value

Categories : Vb.Net

Function taking lambda expression
There is two things in your code that will not work. First, when passing a lambda function as argument, I suggest using Template. The standard library on Microsoft seems to use this method for std::for_each for example. And : When function template has a return type, which cannot be deduced from arguments, or when function template doesn't have any argument, the type cannot be deduced by the compiler. This function will require template type argument specification. Take a look at this example : template<class Tout, class Tin, class Fun> // ^^^^^^^^^^^ // Note that I changed the order of the types std::vector<Tout> map( const std::vector<Tin>& in, Fun mapper ) { // ^^^^^^^^^^ std::vector

Categories : C++

Get duplicated row in two datatable using lambda expression
I would try following: ' prepare HashSet from keys from table2 ' Dim table2Keys = new HashSet(Of Tuple(Of String, String)) set.UnionWith(table2.AsEnumerable().Select(Function(x) Tuple.Create(x("item1"), x("item2")) ' search table1 for duplicates ' Dim result = table1.Where(Function(x) table2Keys.Contains(Tuple.Create(x("item1", y("item2"))) It should have better performance then using Any, because HashSet lookup can be done in O(1).

Categories : Vb.Net

Model error, lambda expression
It looks like you've created an anonymous type needlessly with this line: .Select(s => new { s.Modulos.Modulos}) Try instead simply (should return an IEnumerable<Modulos>): .Select(s => s.Modulos.Modulos)

Categories : C#

Yielding from inside a lambda expression in F#
You have to yield the uncloned array. There is the obvious strange behaviour in that if you call toList on the sequence then you get an array of the last value of the array. So the first thing you have to do is Seq.map it with the clone function. Also I don't think there is a need to make your function recursive if you are allready working with mutables. let permutations (alphabet:'a array) = let swap i j = let aux = alphabet.[i] alphabet.[i] <- alphabet.[j] alphabet.[j] <- aux let rec permutations' n = seq { if n = alphabet.Length then yield alphabet else for i in n..(alphabet.Length-1) do swap n i yield! permutations' (n+1)

Categories : Dotnet

How to specify an Include inside a lambda expression
Have you tried this? return project.Servers .Include(a => a.OperatingSystem) .Include(a2 => a2.DataCenter) .Include(a3=>a3.Rack) .Include(a4=>a4.ServerModel) .Include(a5=>a5.Technology) .Include(a6=>a6.VirtualMachines) .Include(a7=>a7.TechnologyStatu) .Include(a8=>a8.TechnologyBackUpStatu) .Include(a9=>a9.TechnologyRole) .Where(srv => srv.Rack.RackID == id);

Categories : C#



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