|
|
November 2008 - Posts
-
Silverlight lacks XPath support in LinqToXML. I need to be able to do dynamic queries over xml for a medical application, where the queries themselves are stored in XML. An example of this type of query is a rule for when a certain test (in this casea pap smear) is needed: match="/root[not(age<21) and gender='female' and age<30 and not(psh/_psh[contains(@title,'hysterectomy')])]" My goal is to develop an Xpath to Linq converter to use in Silverlight. Using Infix to Postfix, - I've been able Read More...
|
-
Hi! First of all I apologize to open a new thread about this topic! As I already wrote here http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=3170303&SiteID=1 , I'd like to use LinqToXsd to read and expecially write Entity Framework's .edmx files. When building the project in Visual Studio 2008 and LinqToXsd Alpha 0.2, I get this error: Error 1 System.InvalidOperationException: Collection was modified. Enumeration operation may be not execute. \linq2xsd_2\linq2xsd_2\LinqToXsd linq2xsd_2 So, i Read More...
|
-
LINQ to XML Hi, I'm trying to find "UD" and "OL" elements in this xml structure: Username ="UD" /> Username ="OL" /> Username ="SD" /> ... because UD and OL have to be parameters, I would like to put them into an array: string[] Usernames = new String[2]; Usernames[0] = "UD"; Usernames[1] = "OL"; I can do this query: var q = from c in loaded.Descendants("Item") where ( (string)c.Attribute("UserName") == Usernames[0] || (string)c.Attribute("UserName") == Usernames[1] ) but how would be great if I Read More...
|
-
I would like to write such code without foreach which calculates the following: // assume that the lists are equal length given IEnumerable a = {1,2,3}; IEnumerable b = {3,4,5}; I would like to get IEnumerable c = {1+3, 2+4, 3+5}; by writing down something similar to this: var c = a.Combine(b, (a_i, b_i) => a_i + b_i); another usage of this would be: given IEnumerable a = {1,2,3,4,5,6,7}; IEnumerable b = new bool[]{true, true, false, true, false, false, true}; I would like to get IEnumerable c = Read More...
|
-
Hi there, I have a problem with my syntax I think... actually its probably more but I am too inexperienced to know it. I can obtain a result with the following: Code Snippet Dim TEST2 = From client In db.clients _ Select client.client_no, _ accountType = client.type, _ Name = If (client.first_name = "" , client.last_name, client.first_name & " " & client.last_name), _ address = concatinateAddress(client.address1, client.address2, client.suburb, client.state, client.postcode), _ phone = client.phone_business, Read More...
|
-
I would venture to say 99% plus of relations are one-to-many. There is no direct model for many-to-many (two one-to-many relations are used) and most folks plunk data that is explicit to a single record, right in the single record (surprise!). Not that one-to-one does not have organizational benefits, but that's beside the point. When the designer sees a foreign key relation it should assume a uni-directional one-to-many relation. Read More...
|
-
Hello, How do I create a transient class that represents a limited set of database columns when performing a particular query? I am using LINQ with VB. Currently I only know how to represent columns from a single database table: Partial Public Class Class1 Public Shared Function CategoriesTable() As IEnumerable( Of Category) Dim dc As New DataClassesDataContext() Dim query = From m In dc.Categories Select m Return query End Function End Class Read More...
|
-
Hi all, I use: IList resultList = DataContext.ExecuteQuery(query.ToString()).ToList(); But unfotunately this statement throws an illegal cast exception with certian DTOs. The propertyname match exactly the column names of the result set so it must have something to do with the datatypes. I want to use bool? (nullable) in my DTOs for fields which are nullable in my database. So could it be aproblem for ExecuteQuery to cast from "bool nullable in DB" to "bool?". Unfortunetely i am not able to drill Read More...
|
-
I've got a strange problem, in my web application i use LINQ for selecting items from the database, while using regular sql to insert and/or update. The problem is that when i update the database through the SQL Server Management studio, LINQ still selects the old values, until in like one minute, where LINQ selects the updated values. It is as if LINQ caches the values or something similar. This is very unpractical.Any ideas what the problem could be? Thanks in Advance. Read More...
|
-
Hi , I wonder if there is someone can help me in this, I have a table called ControlInfo where I store controls rendered in my application from database with the following structure : ControlID Text ParentID 1 Country 0 2 State 1 3 Suburb 2 4 Street 3 How can I use linq to sql to build a tree of controls based on the table showing above . how to populate the following object structure: Class ControlTree { Public int ControlID { get; set; } public string ControlText { get; set;} Public IList SubControls Read More...
|
-
Hi, I am looking for a way to generically reset all eager loaded associations of any given linq entity. In other words, I have a linq entity of some unknown type. I know how to iterate all associations, but I do not know how to reset them so the latest data for the associated entities will be reloaded from the database upon the next access to child entities. Codewise I am looking for something like this: //recurse all 1:n associations foreach (MetaAssociation association in context.Mapping.GetMetaType(typeof(TEntityType)).Associations) Read More...
|
-
Hi Guys, I've recently discovered that .Max(...) and Math.Max(...) operate slightly differently when dealing with doubles. Code Snippet Console .WriteLine( "Linq max: " + new double [] { 20 , double .NaN }.Max()); Console .WriteLine( "Linq min: " + new double [] { 20 , double .NaN }.Min()); Console .WriteLine( "Math max: " + Math .Max( 20 , double .NaN)); Console .WriteLine( "Math min: " + Math .Min( 20 , double .NaN)); Is this by design? If so, what's the logic here? Or is this a bug? Cheers, James Read More...
|
-
Hello, I have two collections. I want to use LINQ and query against them both. I want to select only items from the first collection where the same column in both collections have the same values. These collections are List(Of MyClass). Example, this was my stab at it. Code Snippet Dim clientQuery = From clientACustomer In clientACustomers _ Where clientACustomer.CustomerID <> ( From clientBCustomer In clientBCustomers Select clientBCustomer.CustomerID) _ Select clientACustomer Any help would be Read More...
|
-
Just curious on different point of views to accomplish the following. I am learning LINQ and LINQtoSQL while working on a small proof of concept application and trying to figure out the best way to model something. Say you have a couple of tables like Customer and Supplier with a bunch of columns in each . Both of these 'objects' need an address (or multiple addresses), so you would create a table Address so you can store both Customer and Supplier addresses in one table. What would be the cleanest Read More...
|
-
Hi all, I have a problem using LinqToSql to cancel an insert i've made to a table of my db. Ok let's say my db has the following structure: Contact Table and Contact_Office Table (that contains work related informations) So one Contact could have multiple Contact_Office information. I'm trying to had some code that will allow me to add a new Contact_Office but i want to be able to cancel this change if the user Click the Cancel Changes button. When i Cancel the changes, i want only the my object Read More...
|
-
Visual Basic 9.0 added many language features that allow us to write in the functional style in a natural and expressive way. The value of programming in the functional style has been apparent to me for some time, and VB developers can realize the same benefits as C# developers, so I’ve written a tutorial for VB developers: Query Composition using Functional Programming Techniques in VB 9.0 . This tutorial is a rewrite of a tutorial that I wrote in the early part of 2008, Query Composition using Read More...
|
-
Autocompletion for LINQPad is finally a reality! (Albeit for a small fee). My sincere thanks to all the beta testers - as well as those who have waited patiently all these months. (Incorporating autocompletion turned into a non-trivial integration project!) Download from here: www.linqpad.net As always, let me know if you have any suggestions. Regards Joe Read More...
|
-
I've built a data access layer based on LINQ-To-SQL, where each class (obviously) maps to a table in the database. Some of these classes conform to an Interface ISecurable. These are records in the database that are controlled be a separate security system. I can easily tell whether a user has access to an a specific record by passing the record object and the current user to a static method that returns a boolean value. From the data context and each of the LINQ-To-SQL partial classes I can easily Read More...
|
-
When creating a LINQ to SQL class (a dbml file), and using the Server Explorer to grab your tables/stored procedure, Visual Studio will usally create a new connection string if it doesnt match a string already in your web.config and you get this warning: The objects you are adding to the designer use a different data connection than the designer is currently using. Do you want to replace the connection used by the designer? When you have a project with multiple people working on it, this gets a little Read More...
|
-
Hi all, I need a service which has both NetTcpbinding and HttpBinding.. (Eg) For silverlight application i need to call the HttpService and for WPF application i need to call the netTcpBinding(But the Service should be same where as the Calling method should be different).. Is it possible.. Can somebody explain with Code?? Thanks.. Read More...
|
-
I have a linq query with an orderby. I'm expecting linq to optimize the code, so the orderby descending and the a call to First() are optimized against each other to form a Max operation, which is algorithmically is a linear time operation, not a log(N) like orderby on it's own. Is my expectation correct, or i'm expecting too much from linq? Here is the code i'm using, which i believe can work as a linear time operation: using System; using System.Linq; using System.Text.RegularExpressions; namespace Read More...
|
-
I am trying to implement the following SQL in Linq. Table alias tm is a junction table between table t and table m SELECT t . Title , m . Publisher , t . Status , m . Type FROM Title_tab t , Title_Mkt_tab tm , Mkt_tab m WHERE t . Title_ID = tm . Tm_Title_ID AND m . Mkt_ID = tm . Tm_Mkt_ID The 3 tables have the following DataContext: private DataClasses1DataContext title = new DataClasses1DataContext (); private DataClasses1DataContext mkt = new DataClasses1DataContext (); private DataClasses1DataContext Read More...
|
-
Hi and mtia. I have a query below, where I would like to return not just a string but also an int value. These fields are bound to a combox box in a different element, how could I make this work? I would like to add type. intMediaTypeID to my select. Code Snippet public static IEnumerable string > MediaTypeList() { string constring = ConfigurationManager . ConnectionStrings[ "MediaConnectionString" ] . ConnectionString; Media db = new Media (constring); IEnumerable string > query = from type in db Read More...
|
-
I'm going nuts trying to get this to work and I've distilled it down to the simplest possible example. I want to execute a stored procedure (SQL Server 2005) and return rows from a table. I've added the Linq-to-SQL classes and dragged the table and stored procedure onto the work surface. My stored procedure looks like: Code Snippet CREATE PROCEDURE GetCategories AS BEGIN SET NOCOUNT ON ; SELECT * FROM Category END GO The table looks like: Code Snippet CREATE TABLE [dbo] . [Category] ( [CategoryId] Read More...
|
-
Hello All, I am fairly new to programing and just have, what I hope, is a simple question. I have a program that parses data and puts it in a Dictionary<>, I was wondering how I would go about using LINQ to SQL to put this data into a database? I am able to use LINQ to run different queries against the data, but putting it into a database seems to be more complicated. Thanks. Read More...
|
-
The LINQ IQueryable Toolkit is now a CodePlex project. http://www.codeplex.com/IQToolkit Going forward this will the be official site to find the latest greatest source bits. I'll continue to post here about the toolkit, how to use it and to show off...( read more ) Read More...
|
-
Hey :) What is the best way to execute linq queries aganst an object implementing the following methods only: public virtual System.Collections.IEnumerator GetEnumerator() public virtual object this[int Index] { get; } public virtual int Count { get; } Is there a better solution, than creating a proxy? TIA Read More...
|
-
Hi, I m new to Linq - SQL. I just want to retrieve 1:m relational data using linq to sql using strored proc. In my scenario, I have two tables "PetLovers" and "Pets". For each pet lover there can be multiple pets. The primary key of "PetLovers" is a forign key for "Pets". I used the O/R designer to create the data context. As I expected, I got a "PetLovers" class whch has a field called "Pets". And here my problem comes into picture. I want to return a paticular "PetLover" and All "Pets" associated Read More...
|
-
I recently posted some code that allows you to use LINQ to query Excel tables . The source for these queries is the Open XML document – you don’t need to involve the Excel application to query the data in these tables. In that post, I presented a few examples of queries of various types. This post shows a join of two tables using the extension methods and classes presented in that post. The source for this query is a spreadsheet where I imported two columns of the Northwind data into two worksheets. Read More...
|
-
I have the following code: Dim dc = New DataClassesDataContext Dim q = From s In dc.MyTable _ Select s.Field _ Distinct ddlList.DataSource = q ddlList.DataBind() I have called the code above from the page load event and the ddlList_load event. I notice that it runs the code initially on load and then again when an item is selected from the list in either of the events above. In running through the code the second time, it resets the item in the dropdownlist so that the first item in the list is returned Read More...
|
-
The ISO announced today the publication of the final text of ISO/IEC 29500, the Office Open XML specification. Doug Mahugh’s post on this has some relevant links regarding the process going forward. As those who have followed my blog know, I’ve had the opportunity to write a fair number of samples, examples, and made contributions to real world applications that are based on the standard. Open XML is a pleasure to work with. When I started participating in this process, the most important thing for Read More...
|
-
I have an XML file that is being created dynamically from multiple sources... The XML file looks much like many of the Microsoft examples (i.e. as seen below). In actuality, there are multiple XML files, each file will be consistent always having "X" number of child elements, but each file may have a different number of child elements. I hope this makes sense.. "file1.xml" will alwyas have root, dataelement, and child1..child5, "file2.xml will always have root, dataelement, and child1...child8... Read More...
|
-
How i can define the func to use this query in a generic form? IQueryable ApplyFunkyQuery ( IQueryable source, Expression> filter1, Expression> filter2, Expression> projection1 ) { return source .Where(filter1) .Select(projection1) .Where(filter2); } thanks Read More...
|
-
The MSXML Team is getting ready to release the MSXML 4.0 Service Pack 3 Beta very soon! MSXML4 SP3 is a complete replacement of previous MSXML 4.0 service packs. The new service pack includes: - A number of security bug fixes - Reliability improvements The Beta will be available on Microsoft Download Center in the very near future. The RTM release is scheduled in the next few months. MSXML 4 SP3 is applicable to the following Windows Operation Systems: • Windows 2000 SP4 • Windows XP SP2 • Windows Read More...
|
-
[Blog Map] This post contains a detailed description of each of the PowerTools for Open XML cmdlets. For an overview and view of PowerTools for Open XML, see Automated Processing of Open XML Documents using PowerShell . For more information on the cmdlets, see: www.codeplex.com/powertools . Set-OpenXmlCustomXmlData The Set-OpenXmlCustomXmlData cmdlet sets or replaces the specified custom XML part in the document. Remove-OpenXmlComment The Remove-OpenXmlComment cmdlet locates and removes comment contents Read More...
|
-
hi all, i have two tables ('TableA', and 'TableC' with a join/cross reference ('TableB' in between them. i'd like to get all of the items from table 'TableA' that are joined to 'TableC', where TableC.SomeID = someID. the query should look something like this: var dbItems = (from i in db.TableA where i.ID == (from j in db.TableB where j.SomeID == someID select j.ID.GetValueOrDefault()) select i); but that doesn't work build because you can't convert IQueriable to int. which makes some sense. so how Read More...
|
-
We are about to implementing IQuaeryable provider for some data source. Linq to SQL, for example translates query to SQL. The question is how to handle a case in the implementaion where different data source type for example SQL-based and not SQL based are present in the same query (for example in a join query)? Read More...
|
-
Hi all, i'm a new one in this forum and in Linq,from few months i study about programmer and i'm learning about Wpf ,before i studied Nhibernate as ORM but it 's not so friendly with WPF so now i begin to study Linq . I been doing an example with the Database of SqlServer mapping with Linq ToSql oafter i create a ObsevableCOllection of the table to GetOrder() and at the end i binding that in a XamDataGrid(Infragistic DataGrid) now i kept in stuck here ,because i don't know how delte,Update and Add Read More...
|
-
I am getting a query from linq that isn't surrounding the string value in this call with single quotes. Anyone know what would cause this? I've verified that boht the parameter and the property AffiliateSiteId are both strings so I'm not sure what else to check. Thanks. public ModuleViewConfiguration GetModuleConfigByModuleId( int ModuleId, string AffiliateSiteId) { var mod = ( from module in tdc.vwModuleLookupByGUIDs where module.ModuleId == ModuleId && module.AffiliateSiteId == AffiliateSiteId.ToString() Read More...
|
-
Pessoal, Tenho um array dentro de um list e gostaria de fazer uma subquery para fazer um select com parâmetros específicos. Recebo uma lista de processos, sendo que na minha classe de Processo contém um array de Itens de Processo (outra classe...que contém atributos específicos) Segue o contexto abaixo: List ----- Processo (int codigo, string descricao, ProcessoItem[ ] itensProcesso) -----------ProcessoItem (int codigo, int codigoFornecedor , string descricao) Seguinte....preciso filtrar uma pesquisa Read More...
|
-
This is the twelfth in a series of posts on how to build a LINQ IQueryable provider. If you have not read the previous posts you probably were born yesterday. How could you possibly make sense of this post without any context at all? At least make an attempt. Sometimes I don't know why I bother. ...( read more ) Read More...
|
-
Could anyone please give me the vb.net equilant of the following c#. I tried a lot of things static void Main() { XDocument items = XDocument .Parse( @" 1000 Item 1000 2000 Item 2000 3000 Item 3000 " ); List string > exclude = new List string > { "1000" , "3000" }; var q = from item in items.Descendants( "item" ) where !exclude.Contains string >(( string )item.Element( "id" )) select item; foreach ( var i in q) Console .WriteLine(i); } Read More...
|
-
I was helped to use LINQ in this thread http://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/cbeca5af-9268-462a-942b-9fa051c8c745 And now I need some more help applying LINQ to this sort! XmlDocument xDoc = new XmlDocument(); string xml = @ " + "\" mat1\ ">" + @ " Monday, November 17, 2008 11:11:59 AM + "\" mat2\ ">" + @ " Tuesday, November 18, 2008 11:11:59 AM + "\" mat3\ ">" + @ " Sunday, November 16, 2008 11:11:59 AM " ; xDoc.LoadXml(xml); Three nodes, out of order. Sorting attempts: Read More...
|
-
Hi, Following examples are not getting compiled in VS 2008. I am getting the compilaion error "Delegate 'System.Func' does not take '2' arguments". I do not find Any or All method in query expression syntax overloaded to take 2 parameters with second parameter as index of the array. Can anyone help? public void Linq68() { int[] numbers = { -9, -4, -8, -3, -5, -2, -1, -6, -7 }; bool negativeMatch = numbers.Any((n, index) => n == -index); Console.WriteLine("There is a number that is the negative of Read More...
|
-
Hi all, I am creating my DataTransferObjects (DTO) right out of a linq to sql statement like: var query = from cm in DataContext ........ select new PersonDTO { } This worked great but now i had to define a member in PersonDTO which cannot be mapped can be mapped to a UDF at the database like: public String GetIDFieldname { get { return "svnr"; } } Although i never touches the Property GetIDFieldname in my linq query i get the error: The member 'DataAccessLayer.Dto.PersonDTO.GetIDFieldname' has no Read More...
|
-
Hi, I am trying to run a linq query on a collection and I want the result to contain all the columns in the collection. But those columns that are not unique across a single rows' aggregation should have the value as null. How can i do this? Is there any expression available using which I can return all such columns for a row (apart from the ones participating in aggregation) which are unique for that aggregated row. eg: 1) The Class: public class Person { string Name string Sex int Age } 2) The Read More...
|
-
da1 = New SqlDataAdapter( "select * from Dept" , conn) da2 = New SqlDataAdapter( "select * from Emp" , conn) da1.Fill(ds, "Dept" ) da2.Fill(ds, "Emp" ) da3.Fill(ds) dv = New DataView(ds.Tables( "Dept" )) dv 1= New DataView(ds.Tables( "Emp" )) dtr = New DataRelation( "r1" , ds.Tables( "Dept" ).Columns( "Dept_No" ), ds.Tables( "Emp" ).Columns( "Dept_No" )) ds.Relations.Add(dtr) dv.RowFilter = "Dept_No=" + TextBox1.Text DataGridView1.DataSource = dv Here I am getting the rows of Dept table only. But Read More...
|
-
Hi, I hav e a wrapper class for Linq results that generally looks like this: Code Snippet public class DataSource { public int Count { get; set; } public IEnumerable Data { get; set; } } Count is the number of Linq results before filtering, so DataSource.Count != DataSource.Data.Count() My problem is that I don't know how to write a query which will create a single instance of my DataSource and populate it with results that I need, here is what I came up so far Code Snippet DataSource query = (from Read More...
|
-
Is it possible to write a method that when passed an IQueryable and a string for a propertyname (as in Wpf binding scenarios) will return the queryable as an OrderBy() for that property? It has to work in querying a database, too. Here's my example that doesn't work: public IQueryable (IQueryable query, string property) { return query.OrderBy(t => typeof(T).GetProperty(property).GetValue(null); } Linq obviously can't convert all that reflection jazz to SQL, how can I do this by manually programming Read More...
|
-
[Blog Map] Excel has a very cool feature where you can declare that a range of cells is a table. It is a feature that allows you to use Excel very much like a database. You can add new rows as necessary, sort the table by columns, do some simple filtering, calculate the sum of columns, and more. Each table has a unique table name, and each column has a name unique to its table. Because these tables are stored in Open XML documents, we can implement some simple extension methods and some classes so Read More...
|
-
When writing queries, just as you sometimes want to skip the first n items in a collection, on occasion you want to skip the last n items. You could certain count the items remaining in the collection, and use the Take operator to take all but the last, but this would mean iterating the collection twice, and would result in uglier code. This post presents the SkipLast Extension method, which allows you to skip the last n items. In the next post, I’m going to present an enhancement to LtxOpenXml classes, Read More...
|
-
How is declarative programming better than imperative? I think is harder to read the code. Harder to debug. Harder to maintain. Read More...
|
-
Hi. I have a generic list of filenames (strings) and want to remove some of them from the list with a regex. Is that convenient to do with a linq query? How? Read More...
|
-
Autocompletion for LINQPad is now in beta and I need 20 more beta testers. If you use LINQPad on a daily basis and would like to give feedback, please contact me at http://www.linqpad.net/feedback.aspx with your full name and e-mail address, by November 18. Note that the timeline is tight: the plan is to go live fairly soon if no major problems show up. Thanks! Joe Read More...
|
-
Hi to all, I read some records from xml file to DataTable, now i want to query to this datatable using Linq so i write like below dtLinq is my Datatable object. Actually all columns are displaying in the combo box( CboField) based on this where condition will change var FilterData = from MyObject in dtLinq.AsEnumerable() where MyObject.Field string >(CboField.SelectedItem) > TxtValue.Text select new { WORKSOURCE = MyObject.Field string >( "WORKSOURCE" ), SITEID = MyObject.Field string >( "SITEID" Read More...
|
-
Attempting to use a linq lambda expression to filter a business object collection. However keep receiving the same error in runtime: "Sys.WebForms.PageRequestManagerServerErrorException: Value cannot be null. Parameter name: arguments." Here is my code snippet: dim fileteredItemSet = ItemSet.Where(Function(x) x.ID = itemID) We can accomplish the same using an iteration, but the LINQ seems faster. Thanks Read More...
|
-
i have downloaded this program, it gives me the warning (can not contact the authentication server to activate my session.) has any one ever seen this and can you help me solve this problem. Read More...
|
-
|
|