Search Results

Search found 18661 results on 747 pages for 'linq to mysql'.

Page 156/747 | < Previous Page | 152 153 154 155 156 157 158 159 160 161 162 163  | Next Page >

  • Making linq avoid using in memory filtering where possible

    - by linqmonkey
    Consider the these two LINQ2SQL data retrieval methods. The first creates a 'proper' SQL statement that filters the data, but requires passing the data context into the method. The second has a nicer syntax but loads the entire list of that accounts projects, then does in memory filtering. Is there any way to preserve the syntax of the second method but with the performance advantage of the first? public partial class Account { public IQueryable<Project> GetProjectsByYear(LinqDataContext context, int year) { return context.Projects.Where(p => p.AccountID==this.AccountID && p.Year==year).OrderBy(p => p.ProjectNo) } public IQueryable<Project> GetProjectsByYear(int year) { return this.Projects.Where(p => p.Year==year).OrderBy(p => p.ProjectNo).AsQueryable() } }

    Read the article

  • linq to sql update data

    - by pranay
    can i update my employee record as given in below function or i have to make query of employee collection first and than i update data public int updateEmployee(App3_EMPLOYEE employee) { DBContextDataContext db = new DBContextDataContext(); db.App3_EMPLOYEEs.Attach(employee); db.SubmitChanges(); return employee.PKEY; } or i have to do this public int updateEmployee(App3_EMPLOYEE employee) { DBContextDataContext db = new DBContextDataContext(); App3_EMPLOYEE emp = db.App3_EMPLOYEEs.Single(e => e.PKEY == employee.PKEY); db.App3_EMPLOYEEs.Attach(employee,emp); db.SubmitChanges(); return employee.PKEY; } But i dont want to use second option is there any efficient way to update data

    Read the article

  • Query decendants in XML to Linq

    - by Gordon
    I have the following xml data: <portfolio> <item> <title>Site</title> <description>Site.com is a </description> <url>http://www.site.com</url> <photos> <photo url="http://www.site.com/site/thumbnail.png" thumbnail="true" description="Main" /> <photo url="http://www.site.com/site/1.png" thumbnail="false" description="Main" /> </photos> </item> </portfolio> In c# I am using the following link query: List list = new List(); XDocument xmlDoc = XDocument.Load(HttpContext.Current.Server.MapPath("~/app_data/portfolio.xml")); list = (from portfolio in xmlDoc.Descendants("item") select new PortfolioItem() { Title = portfolio.Element("title").Value, Description = portfolio.Element("description").Value, Url = portfolio.Element("url").Value }).ToList(); How do I go about querying the photos node? In the PortfolioItem class I have a property: List Photos {get;set;} Any ideas would be greatly appreciated!

    Read the article

  • Grabbing Just The Top Entry From A LINQ Query

    - by Soo
    I basically have a lot of poorly designed code to do something that, I'm sure, can be done far more elegantly. What I'm trying to do is grab the last date from a database table. var Result = from a in DB.Table orderby a.Date descending select new {Date = a}; foreach(var Row in Result) { LastDate = Row.Date.Date; break; } Basically, there's a foreach loop that is designed to run only once. Crappy code! What's a "best practice" way to accomplish the same thing?

    Read the article

  • How to use the IN operator in linq

    - by Hallaghan
    I'm querying a view and filtering the results with a column named status. I'd like to query it so I can search for rows with different status, by using the IN operator as I'd do in SQL. As so: SELECT * FROM VIEW WHERE Status in ('....', '.....') How can I achieve this?

    Read the article

  • C# LINQ join With Just One Row

    - by Soo
    I'm trying to make a query that grabs a single row from an SQL database and updates it. TableA AId AValue TableB BId AId BValue Ok, so TableA and TableB are linked by AId. I want to select a row in TableB based on AValue using a join. The following query is what I have and only grabs a value from TableB based on AId, I just don't know how to grab a row from TableB using AValue. I know you would need to use a join, but I'm not sure how to accomplish that. var row = DbObject.TableB.Single(x => x.AId == 1) row.BValue = 1; DbObject.SubmitChanges();

    Read the article

  • Exploding a range of dates with LINQ

    - by Robert Gowland
    If I have a pair of dates, and I want to generate a list of all the dates between them (inclusive), I can do something like: System.DateTime s = new System.DateTime(2010, 06, 05); System.DateTime e = new System.DateTime(2010, 06, 09); var list = Enumerable.Range(0, (e - s).Days) .Select(value => s.AddDays(value)); What I'm stuck on is that I've got a list of pairs of dates that I want to explode into a list of all the dates between them. Example: {2010-05-06, 2010-05-09}, {2010-05-12, 2010-05-15} should result in {2010-05-06, 2010-05-07, 2010-05-08, 2010-05-09, 2010-05-12, 2010-05-13, 2010-05-14, 2010-05-15} Note the pairs of dates are guaranteed not to overlap each other.

    Read the article

  • LINQ Expression help with Func TEntity,TType

    - by Chris Conway
    I have a repository method that accepts an order by parameter in the form: public IEnumerable<TEntity> Get<TEntity>(Expression<Func<TEntity,string>> orderBy) Now that works fine when trying to sort by a property of type string, var entities = rep.Get(x => x.Name); but what if i want to sort by double or int or any other type. Doing something like var entities = rep.Get(x => x.Price); obviously throws a compile error saying I can't convert double to string. How can I make this more generic so I can sort by any property in my entity, or at least the properties where the type implements IComparable or something similar?

    Read the article

  • C# - LINQ Including headache...

    - by ebb
    Case can have many Replies and one User, Replies can have one Case and one User, One User can have many Replies and many Cases. ObjectSet <= Case Object (IDbSet) ObjectSet.Include(x => x.User).Include(x => x.Replies).FirstOrDefault(x => x.Id == caseId); But the User Object for each Reply are not included? Only the User object for Case is Included? How would I include the User objects for the Replies too? Thanks in advance!

    Read the article

  • Linq Return node level of hierarchical xml

    - by Ryan
    In a treeview you can retrieve the level of an item. I am trying to accomplish the same thing with the given input being an object. The XML data I will use for this example would be something like the following <?xml version="1.0" encoding="utf-8" ?> <Testing> <Numbers> <Number val="1"> <Number val="1.1"> <Number val="1.1.1"> <Number val="1.1.2" /> <Number val="1.1.3" /> <Number val="1.1.4" /> </Number> </Number> <Number val="1.2" /> <Number val="1.3" /> <Number val="1.4" /> </Number> <Number val="2" /> <Number val="3" /> <Number val="4" /> </Numbers> <Numbers> <Number val="5" /> <Number val="6" /> <Number val="7" /> <Number val="8" /> </Numbers> </Testing> This one is kicking my butt!

    Read the article

  • SQL and/or LINQ query for determining daily increases in viewers

    - by Gio
    We're montioring usage of a certain resources by monitoring users logins (We can see user logins growing daily). After filtering out repeat inter day logins for users, we'd like to track the # of users using the service each day, and then using that info to determine overall incremental gains for each calendar day. Our table is pretty simple: class ServiceLogin { String login; DateTime loginTime; }

    Read the article

  • How do I switch the table that is queried with linq-to-sql

    - by Ian Ringrose
    We have two tables with the same set of columns; depending on the “type” of object the value is stored in one of the two tables. I wish to use common code to access these two tables. If I was using “raw sql” I could just use String.Format() to change the table name. (Likewise for updates etc) The two separate tables are needed as the data access patterns are very different for the common queries on the two tables and therefore different indexes are needed. “Views” and “instead of triggers” etc to make the tables look like a single table are not liked here. A lot of our customers use low end version of SqlServer so we cannot use partition tables.

    Read the article

  • Using Linq to filter parents by their children

    - by Nick L
    Having some problems with my Silverlight app (with RIA services) filtering my results. The idea is on the client I set up the EntityQuery and its filters and call load. However this isn't working for me. Heres my code. public void FireQuery(string filterValue) { EntityQuery<Parent> query = m_ParentDomainContext.GetParentQuery(); query = query.Where(p => p.Children.Any(c => c.Name.Contains(filterValue))); m_ParentDomainContext.Load(query, Query_Completed, null); } Compiles just fine, however, runtime I get "Query operator 'Any' is not supported." Exception. Does anyone know of a good way to filter like this? Again, I'm looking for a way to set this up on the client.

    Read the article

  • LINQ Query to filter DTO

    - by brabone
    I have an array...and I need to exclude all the items in this array of string from the masterList.customField as shown below string[] excludeItem = {"a","b","c"}; CustomDTO[] masterList = service.LoadMasterList(); masterList.Where(c=> masterList.customField NOT IN excludeItem How do I achieve the NOT IN part above?

    Read the article

  • Linq.Where-to-SQL on a text field comparing to a list of values

    - by StampedeXV
    Customer.text is a field in an T-SQL DB (that I do not control and thus may not alter) of type "text". I'd like to do something like this: List<string> compare = new List<string>(); compare.Add("one"); compare.Add("two"); var q = from t in customer where t.text.Contains( compare.First()) select t; this will work. But now I'd like to do something like: (!NOT WORKING!) var q = from t in customer where compare.Contains( t.text ) select t; How can I achieve this? Is it even possible?

    Read the article

  • 'Random' Orderby in webservice using LINQ To Entities

    - by MrDean
    Morning all Now I know there is a reason to this odering but my tiny little brain can't get my head around it. I am using a webservice to pull through data to a webp[age and have the following that is so far pulling data through from UUF1: public string[] GetBuyer(string Memberkey) { try { WebService.EntitiesConnection buyer = new WebService.EntitiesConnection(); return buyer.tblProducts .Where(p => p.MemberId == Memberkey) .OrderBy(p => p.UnitUserfield1) .Select(p => p.UnitUserfield1) .Distinct() .ToArray(); } catch (Exception) { return null; } } This works fine and pulls the data through but in a strange order. Where I would expect results of A B C D E F, it appears to be returning A C E B D F. Could someone point out the error in my ways please?

    Read the article

  • LINQ to Entites: Doing a count over one-to-many relationships

    - by chris
    I have a couple of tables where there are one to many relationships. Let's say I have a Country table, a State table with a FK to Country, and a City table with a FK to State. I'd like to be able to create a count of all Cities for a given country, and also a count of cities based on a filter - something like: foreach( var country in Model.Country ) { total = country.State.All().City.All().Count() ; filtered = country.State.All().City.Any(c=>c.field == value).Count(); } Obviously, this doesn't work - is there any way to do this?

    Read the article

  • Using LINQ, need help splitting a byte array on data received from Silverlight sockets

    - by gcadmes
    The message packats received contains multiple messages deliniated by a header=0xFD and a footer=0xFE // sample message packet with three // different size messages List<byte> receiveBuffer = new List<byte>(); receiveBuffer.AddRange(new byte[] { 0xFD, 1, 2, 0xFE, 0xFD, 1, 2, 3, 4, 5, 6, 7, 8, 0xFE, 0xFD, 33, 65, 25, 44, 0xFE}); // note: this sample code is without synchronization, // statements, error handling...etc. while (receiveBuffer.Count > 0) { var bytesInRange = receiveBuffer.TakeWhile(n => n != 0xFE); foreach (var n in bytesInRange) Console.WriteLine(n); // process message.. // 1) remove bytes read from receive buffer // 2) construct message object... // 3) etc... receiveBuffer.RemoveRange(0, bytesInRange.Count()); } As you can see, (including header/footer) the first message in this message packet contains 4 bytes, and the 2nd message contains 10 bytes,a and the 3rd message contains 6 bytes. In the while loop, I was expecting the TakeWhile to add the bytes that did not equal the footer part of the message. Note: Since I am removing the bytes after reading them, the header can always be expected to be at position '0'. I searched examples for splitting byte arrays, but non demonstrated splitting on arrays of unknown and fluctuating sizes. Any help will be greatly appreciated. thanks much!

    Read the article

  • LINQ query to navigate an object hierachy

    - by TesterTurnedDeveloper
    Let's say I have an object graph of Countries / States / Cities, like below: public class City { public string Name { get; set; } } public class State { public List<City> Cities { get; set; } } public class Country { public List<State> States { get; set; } } Is there a simple way to query a List<Country> to get all the cities?

    Read the article

  • Linq to Sql GroupJoin Paging oddity

    - by OllyA
    I have noticed a strange Sql Translation in a LinqToSql Query I was trying to optimise. If I execute the following Recipients.GroupJoin( RecipientAttributes, x => x.Recipient_Id, y => y.Recipient_Id, (x,y) => new {Recipient = x, Attributes = y}) .Skip(1) .Take(1000) It executes in a single query as expected. However Recipients.GroupJoin( RecipientAttributes, x => x.Recipient_Id, y => y.Recipient_Id, (x,y) => new {Recipient = x, Attributes = y}) .Skip(0) .Take(1000) executes in a separate query for each Attributes selection. Removing the Skip(0) makes no difference either. Can anyone explain this and is there something I can do to get the first page query executing in a single sql statement?

    Read the article

  • "And" condition in C#/LINQ Query

    - by user1213055
    partial void PrintDocLetter1_CanExecute(ref bool result) { if (this.PatientsMasterItem.DoctorsMasterItem != null) { var Doctor = PatientsMasterItem.DoctorsMasterItem; var PatientList = Doctor.PatientsMasterItem; var Letters = PatientsMasterItem.LettersSentItem; if ((PatientList.Count() > 1) && (Letters.Any(i => i.LetterType == "DoctorLetter1"))) { result = false; } else { result = true; } } } I think something is wrong with my second condition. I'm trying to find two things. 1) Doctors with more than 1 patient. 2) Among those patients whether a lettertype called "DoctorLetter1" has been sent or not. The above code is working good for that particular record but not working other patients with same doctors where patient1 has already been sent with DoctorLetter1.

    Read the article

  • GetByLatest in LINQ ?

    - by Ritz
    hello all, Please provide me a solution for GetByLatest it is giving me an error How to use this "GetByLatest" IList<IRss> news = new Trytable().GetByLatest().Cast<IRss>().ToList(); please help me Thanks Ritz

    Read the article

  • Rewriting a statement using LINQ(C#)

    - by Thinking
    Is it possible to write the folowing using lambda(C#) private static void GetRecordList(List<CustomerInfo> lstCustinfo) { for (int i = 1; i <= 5; i++) { if (i % 2 == 0) lstCustinfo.Add(new CustomerInfo { CountryCode = "USA", CustomerAddress = "US Address" + i.ToString(), CustomerName = "US Customer Name" + i.ToString(), ForeignAmount = i * 50 }); else lstCustinfo.Add(new CustomerInfo { CountryCode = "UK", CustomerAddress = "UK Address" + i.ToString(), CustomerName = "UK Customer Name" + i.ToString(), ForeignAmount = i * 80 }); } }

    Read the article

< Previous Page | 152 153 154 155 156 157 158 159 160 161 162 163  | Next Page >