Search Results

Search found 2155 results on 87 pages for 'mathematical expressions'.

Page 19/87 | < Previous Page | 15 16 17 18 19 20 21 22 23 24 25 26  | Next Page >

  • 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

  • Mathematics - Why is Differential Calculus (MVP) in PHP a tabu?

    - by Email
    Hi I want to do a Mean-Variance-Optimization (Markowitz) but i never found anything written in php that does this. MVP needs differential calculus. Can it be done in php and why arent there any classes/works from universities? For a webapplication (regarding performance) would another language be the better choice to handle heavy calculations? Thanks so much for any help/answer on this

    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

  • Dynamic expression tree how to

    - by Savvas Sopiadis
    Hello everybody! Implemented a generic repository with several Methods. One of those is this: public IEnumerable<T> Find(Expression<Func<T, bool>> where) { return _objectSet.Where(where); } Given to be it is easy to call this like this: Expression<Func<Culture, bool>> whereClause = c => c.CultureId > 4 ; return cultureRepository.Find(whereClause).AsQueryable(); But now i see (realize) that this kind of quering is "limiting only to one criteria". What i would like to do is this: in the above example c is of type Culture. Culture has several properties like CultureId, Name, Displayname,... How would i express the following: CultureId 4 and Name.contains('de') and in another execution Name.contains('us') and Displayname.contains('ca') and .... Those queries should be created dynamically. I had a look in Expression trees (as i thought this to be a solution to my problem - btw i never used them before) but i cannot find anything which points to my requirement. How can this be costructed? Thanks in advance

    Read the article

  • Adding an equation or formula to a figure caption in LaTeX

    - by gotgenes
    I have a figure in LaTeX with a caption to which I need to add a formula (equation* or displaymath environments). For example: \documentclass[12pt]{article} \begin{document} \begin{figure}[tbph] \begin{center} %... \end{center} \caption{As you can see \begin{displaymath}4 \ne 5\end{displaymath} } \label{fig:somefig} \end{figure} \end{document} This makes pdflatex angry, though it will produce a PDF. ! Argument of \@caption has an extra }. <inserted text> \par l.9 } What's the right way to go about adding an equation to a figure caption? NOTE: Please do not suggest simply using the $ ... $ math environment; the equation shown is a toy example; my real equation is much more intricate. See also: Adding a caption to an equation in LaTeX (the reverse of this question)

    Read the article

  • How do I tell if an action is a lambda expression?

    - by Keith
    I am using the EventAgregator pattern to subscribe and publish events. If a user subscribes to the event using a lambda expression, they must use a strong reference, not a weak reference, otherwise the expression can be garbage collected before the publish will execute. I wanted to add a simple check in the DelegateReference so that if a programmer passes in a lambda expression and is using a weak reference, that I throw an argument exception. This is to help "police" the code. Example: eventAggregator.GetEvent<RuleScheduler.JobExecutedEvent>().Subscribe ( e => resetEvent.Set(), ThreadOption.PublisherThread, false, // filter event, only interested in the job that this object started e => e.Value1.JobDetail.Name == jobName ); public DelegateReference(Delegate @delegate, bool keepReferenceAlive) { if (@delegate == null) throw new ArgumentNullException("delegate"); if (keepReferenceAlive) { this._delegate = @delegate; } else { //TODO: throw exception if target is a lambda expression _weakReference = new WeakReference(@delegate.Target); _method = @delegate.Method; _delegateType = @delegate.GetType(); } } any ideas? I thought I could check for @delegate.Method.IsStatic but I don't believe that works... (is every lambda expression a static?)

    Read the article

  • How to use constraint programming for optimizing shopping baskets?

    - by tangens
    I have a list of items I want to buy. The items are offered by different shops and different prices. The shops have individual delivery costs. I'm looking for an optimal shopping strategy (and a java library supporting it) to purchase all of the items with a minimal total price. Example: Item1 is offered at Shop1 for $100, at Shop2 for $111. Item2 is offered at Shop1 for $90, at Shop2 for $85. Delivery cost of Shop1: $10 if total order < $150; $0 otherwise Delivery cost of Shop2: $5 if total order < $50; $0 otherwise If I buy Item1 and Item2 at Shop1 the total cost is $100 + $90 +$0 = $190. If I buy Item1 and Item2 at Shop2 the total cost is $111 + $85 +$0 = $196. If I buy Item1 at Shop1 and Item2 at Shop2 the total cost is $100 + $10 + $85 + $0 = 195. I get the minimal price if I order Item1 and Item2 at Shop1: $190 What I tried so far I asked another question before that led me to the field of constraint programming. I had a look at cream and choco, but I did not figure out how to create a model to solve my problem. | shop1 | shop2 | shop3 | ... ----------------------------------------- item1 | p11 | p12 | p13 | item2 | p21 | p22 | p23 | . | | | | . | | | | ----------------------------------------- shipping | s1 | s2 | s3 | limit | l1 | l2 | l3 | ----------------------------------------- total | t1 | t2 | t3 | ----------------------------------------- My idea was to define these constraints: each price "p xy" is defined in the domain (0, c) where c is the price of the item in this shop only one price in a line should be non zero if one or more items are bought from one shop and the sum of the prices is lower than limit, then add shipping cost to the total cost shop total cost is the sum of the prices of all items in a shop total cost is the sum of all shop totals The objective is "total cost". I want to minimize this. In cream I wasn't able to express the "if then" constraint for conditional shipping costs. In choco these constraints exist, but even for 5 items and 10 shops the program was running for 10 minutes without finding a solution. Question How should I express my constraints to make this problem solvable for a constraint programming solver?

    Read the article

  • Ruby Design Problem for SQL Bulk Inserter

    - by crunchyt
    This is a Ruby design problem. How can I make a reusable flat file parser that can perform different data scrubbing operations per call, return the emitted results from each scrubbing operation to the caller and perform bulk SQL insertions? Now, before anyone gets narky/concerned, I have written this code already in a very unDRY fashion. Which is why I am asking any Ruby rockstars our there for some assitance. Basically, everytime I want to perform this logic, I create two nested loops, with custom processing in between, buffer each processed line to an array, and output to the DB as a bulk insert when the buffer size limit is reached. Although I have written lots of helpers, the main pattern is being copy pasted everytime. Not very DRY! Here is a Ruby/Pseudo code example of what I am repeating. lines_from_file.each do |line| line.match(/some regex/).each do |sub_str| # Process substring into useful format # EG1: Simple gsub() call # EG2: Custom function call to do complex scrubbing # and matching, emitting results to array # EG3: Loop to match opening/closing/nested brackets # or other delimiters and emit results to array end # Add processed lines to a buffer as SQL insert statement @buffer << PREPARED INSERT STATEMENT # Flush buffer when "buffer size limit reached" or "end of file" if sql_buffer_full || last_line_reached @dbc.insert(SQL INSERTS FROM BUFFER) @buffer = nil end end I am familiar with Proc/Lambda functions. However, because I want to pass two separate procs to the one function, I am not sure how to proceed. I have some idea about how to solve this, but I would really like to see what the real Rubyists suggest? Over to you. Thanks in advance :D

    Read the article

  • How can i filter a list of objects using lamda expression?

    - by Colour Blend
    I know i shouldn't have id's with the same value. This is just fictitious, so overlook that. I have: List<Car> carList = new List<Car>(); carList.Add(new Car() { id = 1, name = "Honda" }); carList.Add(new Car() { id = 2, name = "Toyota" }); carList.Add(new Car() { id = 1, name = "Nissan" }); I want to use Lamda Expression to retreive all cars that have an id of 1. Anticipated Result: -- Id: 1, Name: Honda -- Id: 1, Name: Nissan The problem is more filtering an object list based on a foriegn key. Please help me.

    Read the article

  • Remove duplicate characters using a regular expression

    - by Alex
    I need to Match the second and subsequent occurances of the * character using a regular expression. I'm actually using the Replace method to remove them so here's some examples of before and after: test* -> test* (no change) *test* -> *test test** *e -> test* e Is it possible to do this with a regular expression? Thanks

    Read the article

  • why do we need advanced knowledge of mathematics & physics for programming?

    - by Sumeet
    Guys, I have been very good in mathematics and physics in my schools and colleges. Right now I am a programmer. Even in the colleges I have to engrossed my self into computers and programming things all the time. As I used to like it very much. But I have always felt the lack of advanced mathematics and physics in all the work I have done (Programs). Programming never asked me any advanced mathematics and physics knowledge in what I was very good. It always ask u some optimized loops, and different programming technologies which has never been covered in advanced mathematics and physics. Even at the time of selection in big College , such a kind of advanced knowledge is required. Time by time I got out of touch of all that facts and concepts (advanced mathematics and physics). And now after, 5 years in job I found it hard to resolve Differentiations and integrations from Trigonometry. Which sometimes make me feel like I have wasted time in those concepts because they are never used. (At that time I knew that I am going to be a programmer) If one need to be a programmer why do all this advanced knowledge is required. One can go with elementry knowledge a bit more. You never got to think like scientists and R&D person in your Schols and colleges for being a programmer? Just think and let me know your thoughts. I must be wrong somewhere in what I think , but not able to figure that out..? Regards Sumeet

    Read the article

  • .NET: Best way to execute a lambda on UI thread after a delay?

    - by Scott Bussinger
    I had a situation come up that required running a lambda expression on the UI thread after a delay. I thought of several ways to do this and finally settled on this approach Task.Factory.StartNew(() => Thread.Sleep(1000)) .ContinueWith((t) => textBlock.Text="Done",TaskScheduler.FromCurrentSynchronizationContext()); But I'm wondering if there's an easier way that I missed. Any suggestions for a shorter, simpler or easier technique? Assume .NET 4 is available.

    Read the article

  • .NET C# setting the value of a field defined by a lambda selector

    - by Frank Michael Kraft
    I have a generic class HierarchicalBusinessObject. In the constructor of the class I pass a lambda expression that defines a selector to a field of TModel. protected HierarchicalBusinessObject (Expression<Func<TModel,string>> parentSelector) A call would look like this, for example: public class WorkitemBusinessObject : HierarchicalBusinessObject<Workitem,WorkitemDataContext> { public WorkitemBusinessObject() : base(w => w.SuperWorkitem, w => w.TopLevel == true) { } } I am able to use the selector for read within the class. For example: sourceList.Select(_parentSelector.Compile()).Where(... Now I am asking myself how I could use the selector to set a value to the field. Something like selector.Body() .... Field...

    Read the article

  • What is the easiest way to get the property value from a passed lambda expression in an extension me

    - by Andrew Siemer
    I am writing a dirty little extension method for HtmlHelper so that I can say something like HtmlHelper.WysiwygFor(lambda) and display the CKEditor. I have this working currently but it seems a bit more cumbersome than I would prefer. I am hoping that there is a more straight forward way of doing this. Here is what I have so far. public static MvcHtmlString WysiwygFor<TModel, TProperty>(this HtmlHelper<TModel> helper, Expression<Func<TModel, TProperty>> expression) { return MvcHtmlString.Create(string.Concat("<textarea class=\"ckeditor\" cols=\"80\" id=\"", expression.MemberName(), "\" name=\"editor1\" rows=\"10\">", GetValue(helper, expression), "</textarea>")); } private static string GetValue<TModel, TProperty>(HtmlHelper<TModel> helper, Expression<Func<TModel, TProperty>> expression) { MemberExpression body = (MemberExpression)expression.Body; string propertyName = body.Member.Name; TModel model = helper.ViewData.Model; string value = typeof(TModel).GetProperty(propertyName).GetValue(model, null).ToString(); return value; } private static string MemberName<T, V>(this Expression<Func<T, V>> expression) { var memberExpression = expression.Body as MemberExpression; if (memberExpression == null) throw new InvalidOperationException("Expression must be a member expression"); return memberExpression.Member.Name; } Thanks!

    Read the article

  • How can I use linq to build an object from 1 row of data?

    - by Hcabnettek
    Hi All, I have a quick linq question. I have a stored proc that should return one row of data. I would like to use a lambda to build an object. Here's what I'm currently doing which works, but I know I should be able to use First instead of Select except I can't seem to get the syntax correct. Can anyone straighten me out here? Thanks for any help. var location = new GeoLocationDC(); DataSet ds = db.ExecuteDataSet(dbCommand); if(ds.Tables[0].Rows.Count == 1) { var rows = ds.Tables[0].AsEnumerable(); var x = rows.Select( c => new GeoLocationDC { Latitude = Convert.ToInt32(c.Field<string>("LATITUDE")), Longitude = Convert.ToInt32(c.Field<string>("LONGITUDE")) }).ToList(); if(x.Count > 0 ) { location = x[0]; } Cheers, ~ck }

    Read the article

  • lambda expression for a query on two tables that returns records from one table

    - by peetee
    I have two tables TableA (articles) int id int Type string name and TableB (compatibles) int linked_ID int tableA_ID TableA records: id=1, Type=0, name="ArticleA" id=2, Type=1, name="ArticleB" id=3, Type=2, name="ArticleC" id=4, Type=1, name="ArticleD" TableB records: linked_ID= 1, tableA_ID=2 linked_ID= 1, tableA_ID=3 linked_ID= 1, tableA_ID=4 TableB has a list of arcicels that are compatible to a certain article. I am quite new to queries (didn't need them in my projects yet). But as C# and WPF allow some pretty cool automation with Binding I would like to add a binding that returns the following: Give me all articles that are of Type 1 and compatible to my selected article (id=1). The simple part of it works well (articles has a list of all articles): private ObservableCollection<Article> _articles = new ObservableCollection<Article>(); [fill it with the available articles] and then: comboBoxArticles.ItemsSource = _articles.AsBindable().Where( c => c.Typ == 0 ); How can I extend the Where clause to query another table? Thanks a lot in advance.

    Read the article

  • How to get XML into a Dictionary with an Expression?

    - by DaveDev
    I have the following XML: <PerformancePanel page="PerformancePanel.ascx" title=""> <FundGroup heading="Net Life Managed Funds"> <fund id="17" countryid="N0" index="24103723" /> <fund id="81" countryid="N0" index="24103723" /> <fund id="127" countryid="N0" index="24103722" /> <fund id="345" countryid="N0" index="24103723" /> <fund id="346" countryid="N0" index="24103723" /> </FundGroup> <FundGroup heading="Net Life Specialist Funds"> <fund id="110" countryid="N0" index="24103717" /> <fund id="150" countryid="N0" index="24103719" /> <fund id="119" countryid="N0" index="24103720" /> <fund id="115" countryid="N0" index="24103727" /> <fund id="141" countryid="N0" index="24103711" /> <fund id="137" countryid="N0" /> <fund id="146" countryid="N0" /> <fund id="133" countryid="N0" /> <fund id="90" countryid="N0" /> <fund id="104" countryid="N0" /> <fund id="96" countryid="N0" /> </FundGroup> </PerformancePanel> I can get the data into an anonymous object as follows: var offlineFactsheet = new { PerformancePanels = (from panel in doc.Elements("PerformancePanel") select new PerformancePanel { PerformanceFunds = (from fg in panel.Elements("FundGroup") select new { Heading = (fg.Attribute("heading") == null) ? "" : (string)fg.Attribute("heading"), Funds = (from fund in fg.Elements("fund") select new Fund { FundId = (int)fund.Attribute("id"), CountryId = (string)fund.Attribute("countryid"), FundIndex = (fund.Attribute("index") == null) ? null : new Index { Id = (int)fund.Attribute("index") }, FundNameAppend = (fund.Attribute("append") == null) ? "" : (string)fund.Attribute("append") }).ToList() }).ToDictionary(xx => xx.Heading, xx => xx.Funds)}; I'm trying to change my code such that I can assign the dictionary directly to a property of the class I'm working in, as described in this question. I'd like to have a Dictionary() where each header text is the key to the list of funds under it. I'm having difficulty applying the example in the linked question because that only returns a string, and this needs to return the dictionary. This is the point that I got to before it occurred to me that I'm lost!!!: this.PerformancePanels = doc.Elements("PerformancePanel").Select(e => { var control = (PerformancePanel)LoadControl(this.OfflineFactsheetPath + (string)e.Attribute("page")); control.PerformanceFunds = e.Elements("FundGroup").Select(f => { List<Fund> funds = (from fund in e.Elements("fund") select new Fund { FundId = (int)fund.Attribute("id"), CountryId = (string)fund.Attribute("countryid"), FundIndex = (fund.Attribute("index") == null) ? null : new Index { Id = (int)fund.Attribute("index") }, FundNameAppend = (fund.Attribute("append") == null) ? "" : (string)fund.Attribute("append") }).ToList(); string heading = (e.Attribute("heading") == null) ? "" : (string)e.Attribute("heading"); }).ToDictionary(xx => heading, xx => Funds); return control; }).ToList(); Could someone point me in the right direction please? I'm not even sure if 'Expression' is the right terminology. Could someone fill me in on that too? Thanks.

    Read the article

< Previous Page | 15 16 17 18 19 20 21 22 23 24 25 26  | Next Page >