Search Results

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

Page 115/747 | < Previous Page | 111 112 113 114 115 116 117 118 119 120 121 122  | Next Page >

  • JSINQ (Linq for JavaScript library) sub-queries (how-to)

    - by Tom Tresansky
    I'm using this library: jsinq. I want to create a new object using subqueries. For example, in .NET LINQ, I could do something like this: from a in Attendances where a.SomeProperty = SomeValue select new { .Property1 = a.Property1, .Property2 = a.Property2, .Property3 = (from p in People where p.SomeProperty = a.Property3 select p) } such that I get a list of ALL people where Property3 value matches the attendance's Property3 value in EACH object returned in the list. I didn't see any sample of this in the docs or on the playground. Made a couple tries of it and didn't have any luck. Anybody know if this is possible and how to?

    Read the article

  • VB.NET GroupBy LINQ statement

    - by Jason
    I am having a bear of a time getting this to work. I have a List(Of MyItem) called Items that have a OrderId property on them. From those items, I want to create a list of Orders. Some items will have the same OrderId so I want to try to group by OrderId. I then want to sort by date. Here's what I have so far: Public ReadOnly Property AllOrders() As List(Of Order) Get Return Items.Select(Function(i As MyItem) New Order(i.OrderID)) _ .GroupBy(Function(o As Order) New Order(o.OrderID)) _ .OrderBy(Function(o As Order) o.DateOrdered).ToList End Get End Property This, of course, doesn't compile, and I get the error: Value of type 'System.Collections.Generic.List(Of System.Linq.IGrouping(Of Order, Order))' cannot be converted to 'System.Collections.Generic.List(Of Order))' I've bolded the part where I think the problem is, but I have no idea how to fix it. Also, it used to work fine (except there were duplicate values) before I added the .GroupBy statement. Anyone have any ideas? Thanks

    Read the article

  • T-SQL IsNumeric() and Linq-to-SQL

    - by cdonner
    I need to find the highest value from the database that satisfies a certain formatting convention. Specifically, I would like to fund the highest value that looks like EU999999 ('9' being any digit) select max(col) will return something like 'EUZ...' for instance that I want to exclude. The following query does the trick, but I can't produce this via Linq-to-SQL. There seems to be no translation for the isnumeric() function in SQL Server. select max(col) from table where col like 'EU%' and 1=isnumeric(replace(col, 'EU', '')) Writing a database function, stored procedure, or anything else of that nature is far down the list of my preferred solutions, because this table is central to my app and I cannot easily replace the table object with something else. What's the next-best solution?

    Read the article

  • LINQ Expression not evaluating correctly

    - by WedTM
    I have the following LINQ expression that's not returning the appropriate response var query = from quote in db.Quotes where quote.QuoteStatus == "Estimating" || quote.QuoteStatus == "Rejected" from emp in db.Employees where emp.EmployeeID == quote.EmployeeID orderby quote.QuoteID descending select new { quote.QuoteID, quote.DateDue, Company = quote.Company.CompanyName, Attachments = quote.Attachments.Count, Employee = emp.FullName, Estimator = (quote.EstimatorID != null && quote.EstimatorID != String.Empty) ? db.Employees.Single (c => c.EmployeeID == quote.EstimatorID).FullName : "Unassigned", Status = quote.QuoteStatus, Priority = quote.Priority }; The problem lies in the Estimator = (quote.EstimatorID != null && quote.EstimatorID != String.Empty) ? db.Employees.Single(c => c.EmployeeID == quote.EstimatorID).FullName : "Unassigned" part. I NEVER get it to evalueate to "Unassigned", on the ones that are supposed to, it just returns null. Have I written this wrong?

    Read the article

  • How to aggregate over few types with linq?

    - by Shimmy
    Can someone help me translate the following to one liner: Dim items As New List(Of Object) For Each c In ph.Contacts items.Add(New With {.Type = "Contact", .Id = c.ContactId, .Title = c.Title}) Next For Each c In ph.Persons items.Add(New With {.Type = "Person", .Id = c.PersonId, .Title = c.Title}) Next For Each c In ph.Jobs items.Add(New With {.Type = "Job", .Id = c.JobId, .Title = c.Title}) Next Is it possible to merge them all into one query or method line, I don't really care if this will be done with something other than linq, I am just looking for a more efficient way as I have a long list coming ahead, and the aggregating list will be strongly-typed using Dim list = blah blah

    Read the article

  • Sync Framework,LINQ, and my DAL

    - by Refracted Paladin
    I am creating a WPF app that needs to allow users to work in a temporary disconnected state and I plan to use a Local Database Cache. My question's are about my data access layer. Do you typically create the whole DAL to point at the Cache or both and create a switching mechanism? Is Entity's a good way to go for my DAL against the Cache? I am used to L2S but my understanding is that I can't use that against SQLCE, correct? Thanks! PS: Any good resources out there for using Sync, Linq, and WPF ALL TOGETHER? Tutorials, videos, etc?

    Read the article

  • Using LINQ to SQL with multiple databases

    - by Stuart Ferguson
    I am working on a new project and hoping to use LINQ to SQL for the data access but have come across the following issue. I need to have my application access 3 databases with similar but not the same table structure, for example Database1 and Database 2 has a table called tblCustomer with 2 columns CustomerKey and CustomerName Database2 has a table called tblCustomer with 3 columns CustomerKey, CustomerName and CustomerPostCode I am looking for a solution that will allow me a query all three databases without the need for 3 GetCustomerList functions as Database1 and Database2 could use the same function as are the same structure, with an override function for database 3 to bring back the additional field. Is there a way i can declare a base datacontext class to handle Database 1 and 2 with an inherited version for Database 3. Thanks In Advance Stuart Ferguson

    Read the article

  • Convert XML attributes to a Dictionary in Linq to XML

    - by NateD
    I've got a program that needs to convert two attributes of a particular tag to the key and value of an Dictionary<int,string>. The XML looks like this: (fragment) <startingPoint coordinates="1,1" player="1" /> and so far my LINQ looks something like this: XNamespace ns = "http://the_namespace"; var startingpoints = from sp in xml.Elements(ns+"startingPoint") from el in sp.Attributes() select el.Value; Which gets me a nice IEnumerable full of things like "1,1" and "1", but there should be a way to adapt something like this answer to do attributes instead of elements. Little help please? Thank you!

    Read the article

  • What's the convention for extending Linq datacontext with set based helper operations specific to on

    - by Luke Rohde
    Hi All I might be vaguing out here but I'm looking for a nice place to put set based helper operations in linq so I can do things like; db.Selections.ClearTemporary() which does something like db.DeleteAllOnSubmit(db.Selections.Where(s => s.Temporary)) Since I can figure out how to extend Table<Selection> the best I can do is create a static method in partial class of Selection (similar to Ruby) but I have to pass in the datacontext like; Selection.ClearTemporary(MyDataContext) This kind of sucks because I have two conventions for doing set based operations and I have to pass the data context to the static class. I've seen other people recommending piling helper methods into a partial of the datacontext like; myDataContext.ClearTemporarySelections(); But I feel this makes the dc a dumping ground for in-cohesive operations. Surely I'm missing something. I hope so. What's the convention? TIA

    Read the article

  • How to get index using LINQ?

    - by codymanix
    Given a datasource like that: var c = new Car[] { new Car{ Color="Blue", Price=28000}, new Car{ Color="Red", Price=54000}, new Car{ Color="Pink", Price=9999}, // .. }; How can I find the index of the first car satisfying a certain condition with LINQ? EDIT: I could think of something like this but it looks horrible: int firstItem = someItems.Select((item, index) => new { ItemName = item.Color, Position = index }).Where(i => i.ItemName == "purple") .First() .Position; Will it be the best to solve this with a plain old loop?

    Read the article

  • LINQ-To-SQL and Many-To-Many Relationship Deletions

    - by Jake
    I have a many-to-many relationship between two tables, let's say Friends and Foods. If a friend likes a food I stick a row into the FriendsFoods table, like this: ID Friend Food 1 'Tom' 'Pizza' FriendsFoods has a Primary Key 'ID', and two non-null foreign keys 'Friend' and 'Food' to the 'Friends' and 'Foods' tables, respectively. Now suppose I have a Friend tom .NET object corresponding to 'Tom', and Tom no longer likes pizza (what is wrong with him?) FriendsFoods ff = tom.FriendsFoods.Where(x => x.Food.Name == 'Pizza').Single(); tom.FriendsFoods.Remove(ff); pizza.FriendsFoods.Remove(ff); If I try to SubmitChanges() on the DataContext, I get an exception because it attempts to insert a null into the Friend and Food columns in the FriendsFoods table. I'm sure I can put together some kind of convoluted logic to track changes to the FriendsFoods table, intercept SubmitChanges() calls, etc to try and get this to work the way I want, but is there a nice, clean way to remove a Many-To-Many relationship with LINQ-To-SQL?

    Read the article

  • LINQ aggregate / SUM grouping problem

    - by Chrissi
    I'm having trouble getting my head around converting a traditional SQL aggregate query into a LINQ one. The basic data dump works like so: Dim result = (From i As Models.InvoiceDetail In Data.InvoiceDetails.GetAll Join ih As Models.InvoiceHeader In Data.InvoiceHeaders.GetAll On i.InvoiceHeaderID Equals ih.ID Join p As Models.Product In Data.Products.GetAll On i.ProductID Equals p.ID Join pg As Models.ProductGroup In Data.ProductGroups.GetAll On p.ProductGroupID Equals pg.ID Join gl As Models.GLAccount In Data.GLAccounts.GetAll On pg.GLAccountSellID Equals gl.ID Where (gl.ID = GLID) Select ih.Period,i.ExtendedValue) What I need to really be getting out is ih.Period (a value from 1 to 12) and a corresponding aggregate value for i.ExtendedValue. When I try to Group ih I get errors about i being out of scope/context, and I'm not sure how else to go about it.

    Read the article

  • Using Linq methods causes missing references to DependencyObject in WindowsBase

    - by Jason Coyne
    I have some c# source that I want to compile using CodeDom within my application (for a plugin) Everything works fine, except if I use a Linq extension function on some of my collections var dict = new Dictionary<KeyType, ValueType>(); .... dict.Any(KV=>KV.Key == "Some Key); When I try to compile source that has this code, it CodeDom complains that I am missing a reference to DependencyObject in WindowsBase. I do not understand why this is happening. Neither the Dictionary class, or the Any extension method reference that class, which apparently is part of Windows.Forms I would normally just ignore the quirk, make the CodeDom add a reference and move on, but Apparently WindowsBase is special and is not always distributed and I don't want to cause issues for users that may not have it installed correctly.

    Read the article

  • Mysql and Subsonic 3 with LINQ: Cannot insert rows

    - by Gustavo
    I'm using Susbsonic 3 with the LINQ templates. I've already added a column called 'ID' to my Articles table. When I try to insert a row using the following code var db = new LDB(); int newID = db.Insert.Into<ArticlesTable> ( x => x.Description ).Values( "TestDescription" ).Execute(); I get the following error message Can't decide which property to consider the Key - you can create one called 'ID' or mark one with SubSonicPrimaryKey attribute Any clue on what I'm doing wrong?

    Read the article

  • Linq Query Help Needed

    - by Randy Minder
    Say I have the following LINQ queries: var source = from workflow in sourceWorkflowList select new { SubID = workflow.SubID, ReadTime = workflow.ReadTime, ProcessID = workflow.ProcessID, LineID = workflow.LineID }; var target = from workflow in targetWorkflowList select new { SubID = workflow.SubID, ReadTime = workflow.ReadTime, ProcessID = workflow.ProcessID, LineID = workflow.LineID }; var difference = source.Except(target); sourceWorkflowList and targetWorkflowList have the exact same column definitions. But they both contain more columns of data than what is shown in the queries above. Those are just the columns needed for this particular issue. difference contains all rows in sourceWorkflowList that are not contained in targetWorkflowList Now what I would like to do is to remove all rows from sourceWorkflowList that do not exist in difference. Could someone show me a query that would do this? Thanks very much - Randy

    Read the article

  • LINQ to SQL join when there aren't results

    - by Boarder2
    Given the following database structure I'm trying to write a LINQ query that will return images grouped by tags it's associated with. So far I've got this: var images = from img in db.Images join imgTags in db.ImageTags on img.idImage equals imgTags.idImage join t in db.Tags on imgTags.idTag equals t.idTag where img.OCRData.Contains(searchText.Text) group img by new { t.TagName } into aGroup select new { GroupName = aGroup.Key.TagName, Items = from x in aGroup select new ImageFragment() { ImageID = x.idImage, ScanDate = x.ScanTime } }; Which works great. However, I also want to return Images that do not have any tags associated with them in a group of "(Untagged)" or something. I can't wrap my head around how I would do this without inserting a default tag for every image and that seems like generally not a very good solution.

    Read the article

  • how to read value of an xml node (single) using linq to xml

    - by Wondering
    Hi All, I have a xml structure similar to below one: <test> <test1>test1 value</test1> </test> Now I am reading the value of node using below LINQ to xml code. var test = from t in doc.Descendants("test") select t.Element("test1").Value; Console.WriteLine("print single node value"); Console.WriteLine(test); above code works fine, but here I have one single node, but to retrive value I am using foreach loop, which I dont think is good..any better way of doing the same thing without a foreach loop Thanks.

    Read the article

  • Getting multiple data items in an element with linq to xml

    - by Maestro1024
    Getting multiple data items in an element with linq to xml I have an xml file like this <TopLevel> <Inside> Jibba </Inside> <Inside> Jabba </Inside> </TopLevel> I was given said xml and and want to get all the elements. Here is the code I have. var q = from c in loaded.Descendants("TopLevel") select (XElement)c.Element("Inside"); I tried c.Elements but that did not work. What do I need to do to get all of the internal elements? This code just gets the first "Inside" tag.

    Read the article

  • Linq to SQL Error with Many-to-Many table

    - by Matt Connolly
    I am getting the following error with linq-to-sql when I try to access a many-to-many collection: Members 'Int32 XXX' and 'Int32 YYY' both marked as IsPrimaryKey and IsDbGenerated. The statement is true, in that both of those columns are primary key integers with identity insert. The table I am trying to access has a foreign key to both YYY and ZZZ, and then ZZZ has a foreign key to XXX. There doesn't appear to be anything wrong with my data structure. I tried setting "Child Property" to false on the ZZZ-YYY relationship, but it didn't change anything.

    Read the article

  • Default Object being modified because of LINQ Query

    - by msarchet
    I'm doing the following code to filter a list of objects before it gets sent off to be printed. Dim printList As New List(Of dispillPatient) For Each pat As dispillPatient In patList If (From meds In pat.Medication Select meds Where meds.Print = True).Count > 0 Then Dim patAdd As New dispillPatient patAdd = pat patAdd.Medication = DirectCast((From meds In pat.Medication Select meds Where meds.Print = True).ToList, List(Of dispillMedication)) printList.Add(patAdd) End If Next What is happening is patList, which is my initial list, for every dispillPatient inside of it, that specific patients Medication object (which is another list), is being shorten to the list that is returned to the patAdd object. I think this has something to do with both the way that .NET makes the copy of my pat object when I do patAdd = pat and the LINQ query that I'm using. Has anyone had a similar issue before and\or what can I do to keep my initial list from getting truncated. Thanks

    Read the article

  • what possible workarounds are there for "only parameterless constructors are support in Linq to Enti

    - by Ralph Shillington
    In my query I need to return instances of a class that doesn't have a default constructor (specifically this is in a custom Membership provider, and MembershipUser is the culprit) var users = from l in context.Logins select new MembershipUser( Name, l.Username, // username l.Id, // provider key l.MailTo, l.PasswordQuestion, l.Notes.FirstOrDefault().NoteText, l.IsApproved, l.IsLockedOut, l.CreatedOn, l.LastLoginOn.HasValue ? l.LastLoginOn.Value : DateTime.MinValue, l.LastActivityOn.HasValue ? l.LastActivityOn.Value : DateTime.MinValue, DateTime.MinValue, l.LastLockedOutOn.HasValue ? l.LastLockedOutOn.Value : DateTime.MinValue ); is syntacitally correct, but results in a runtime error as Only parameterless constructors and initializers are supported in LINQ to Entities.

    Read the article

  • Can you update/add records in SQL using a datagridview and LINQ to SQL

    - by Jordan S
    Is it possible to bind a DataGridView to a LINQ to SQL class so that when I make changes to the records in the datagridview it automatically updates the SQL database? I have tried binding the data like this but if I make changes to the data in the datagrid view they do not actually affect the data in the database... BOMClassesDataContext DB = new BOMClassesDataContext(); var mfrs = from m in DB.Manufacturers select m; BindingSource bs = new BindingSource(); bs.DataSource = mfrs; dataGridView1.DataSource = bs;

    Read the article

  • Linq Where Clauses - Better to stack or combine?

    - by burnt_hand
    When writing a method chain for LINQ, I can do the Where statements one of two ways: var blackOldCats = cats.Where(cat => cat.Age > 7 && cat.Colour == "noir" ) Or var blackOldCats = cats.Where(cat => cat.Age > 7).Where(cat.Colour == "noir" ) Are there any benefits of one over the other? Don't worry too much about the datatypes in this example, but if there are issues with datatypes, then that would be good to know too.

    Read the article

  • Insert record in Linq to Sql

    - by Anders Svensson
    Is this the easiest way to insert a record with Linq to Sql when there's a many-to-many relationship, or is there a better/cleaner way? I wasn't sure why things weren't working at first, but when I added a second SubmitChanges() it worked. Why was this necessary? Would be grateful if someone could clarify this a bit! private void InsertNew() { UserPageDBDataContext context = new UserPageDBDataContext(); User user = new User(); ManyToMany.Model.Page page = new ManyToMany.Model.Page(); user.Name = "Madde Andersson"; page.Url = "anderscom/references"; context.Users.InsertOnSubmit(user); context.Pages.InsertOnSubmit(page); context.SubmitChanges(); UserPage userPage = new UserPage(); userPage.UserID = user.UserID; userPage.PageID = page.PageID; user.UserPages.Add(userPage); context.SubmitChanges(); }

    Read the article

  • LINQ to remove duplicated property

    - by Shawn Mclean
    I have a LINQ statement like this: var media = (from p in postService.GetMedia(postId) select new { PostId = postId, SynthId = p.SynthId }); There are many(possibly thousands) of records returned with the same SynthId. I want to select one one, any random one. So when I'm finished, media should contain records with distinct SynthId. SynthId can be null, I want all nulls to be in media (the distinct should not affect them). My DAL is EntityFramework, if that will help. How do I accomplish this in the most efficient way?

    Read the article

< Previous Page | 111 112 113 114 115 116 117 118 119 120 121 122  | Next Page >