|
|
April 2008 - Posts
-
I have a LINQ query that queried 6 tables with inner joins, a where clause and with an orderby clause. The orderby clause ordered on three columns in turn. It all worked wonderfully well, apart from one little thing. Dut to the data in the database, it was returning several duplicate rows. So, I thought I'd use the equivalent to a SELECT DISTINCT. The syntax goes from: var query = a from tableA, ....... select new {x} ; to var query = (a from tableA, ....... select new {x})Distinct() ; Okay, this Read More...
|
-
I have three tables that I want to query When I try: Code Snippet var query = from a in TableA join b in TableB on a.FieldA equals b.FieldX join c in TableC on b.FieldM equals c.FieldR && b.FieldN equals c.FieldS && b.FieldO equals c.FieldT The query starts giving me syntax errors when I try the && b.FieldN equals c.FieldS line I've tried to put in brackets here there and everywhere, but to no avail. Any ideas? I've got around this using the old ANSI syntax (of putting in multiple b.Field? == c.Field?) Read More...
|
-
Hi, I wrote a small test windows mobile application to modify a XML file. Here is the code: Code Snippet using System; using System.Linq; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.Xml.Linq; using System.Xml; namespace xmlCFtest { public partial class Form1 : Form { public Form1() { InitializeComponent(); updateMsg( "14722" , 5); } private void updateMsg( string MsgID, int newStatus) Read More...
|
-
There is a cool add-in for Visual Studio that I use. It is the Open XML Package Editor, which is a graphical treeview based editor for examining and editing Open XML Package files. Once you install the add-in, you can drag an Open XML document into Visual Studio, and browse through the parts, and open specific parts for editing in Visual Studio's great XML editor. Visual Studio doesn't keep the file open, so you can use it in the following scenarios: You can using Word 2007 to create a file, save Read More...
|
-
Hey, I'm using the linq to xsd library in one of my projects. It's a SharePoint project and all the assemblies need to be strong named. I'm referencing the linq to xsd assembly. The problem is that this assembly is not signed. Is it possible to have a signed version of this assembly or is there a way of signing this assembly myself? thanks, Lieven Read More...
|
-
On a whim I decided to attempt to create a phpMyAdmin-like interface using ASP.NET and LINQ. Here is the general idea I was aiming for: Create a normal "LINQ to SQL" class. Load the class into a generic web admin utility. Browse and mange the data via a web page. I didn't want to manually create a LinqDataSource and associate specific tables and columns with DataGrids. I wanted everything to be fetched and generated automatically from the "LINQ to SQL" class. Here is my first attempt at accomplishing Read More...
|
-
Hi! In our ASP.NET project we use CopyToDatatable for generating dynamic excel-exports out of LINQ-queries (SQL). In our LINQ-queries we define which columns to pick. The problem is that the column-order of the datatable does not fit the select order. Example: Code Snippet Dim var = From t In dc.ViewExpenseTemplates _ Where t.ExpenseTemplateID.ToString = ExpTemplId _ Order By t.ExpenseType _ Select t.ExpenseType, _ t.MasterExpenseTypeID, _ t.LimitAmount, _ t.IsManagerInformation, _ t.IsBlockExceed, Read More...
|
-
To date ,the enterprise has been using the standard ADO.net mechanisms of DAtaSet,DAtaAdapters,Commanndsect to retrive and update data in database. what new feature in ADO.net ,in particular Language Integrated Queries(LINQ) . What is the advantages and disadvantages of both approaches ,Anyone can explain it for me and show me some examples Kindly Regards, RedStoo Read More...
|
-
Hi everybody... Now I've trie several times, but I cannot find a proper way to do it. My scenario is: public interface IBuildingUnit { IBuildingUnit AnotherBuildingUnitProxy { get; } } public partial class Wall : IBuildingUnit { // Wall is a partial with the rest of the code hidden away in the DataContext autogenerated designer file // It has the one association (for simplicity) named AnotherBuildingUnit that points to another Wall // I often in my program need to refer to this AnotherBuildingUnit Read More...
|
-
I have a web service with n-tier Architecture as following: Database Stored Procedures Business Entity Classes (more like Data Model) Data Access Classes Business Logic Classes (has 1:1 to Business Entity classes, also has some DTO) Presentation Logic Classes Web service classes I haven't used LINQ (just have read some articles) before but I want to use LINQ in my web service, I am not sure to which layer it will be fit in and basically is there any benefit to do it for me? Probably I can use LINQ Read More...
|
-
I created two tables and a unique index with the transact-sql below. I then ran SqlMetal using the /dbml option. The generated dbml file did not have the association tags. I do not know if this is an error but i suspect that it is since the Query designer showed the proper linkage between the tables graphically and also generated the correct join statement. This test was run using SqlServer Express 2005. I am using SqlMetal provided with Visual Studio 2008 (Not Beta). If I create a foreign key that Read More...
|
-
I created two tables and a unique index with the transact-sql below. I then ran SqlMetal using the /dbml option. The generated dbml file did not have the association tags. I do not know if this is an error but i suspect that it is since the Query designer showed the proper linkage between the tables graphically and also generated the correct join statement. This test was run using SqlServer Express 2005. I am using SqlMetal provided with Visual Studio 2008 (Not Beta). If I create a foreign key that Read More...
|
-
Hi, I have an employees table with self-relationship defining the manager/employee relationship as follows: ID Name ManagerID 1 John -1 2 Jason 1 3 Peter 1 4 Jose 2 How can I use LINQ to convert the above to a hierarchical data structure (to bind to tree, etc.) depicting the manager/employee relationship like this: John Jason Jose Peter Thanks much. Read More...
|
-
HI In the VS 2008 IDE, if I create a Data Connection to a SQL Server's master database, I can't then drill into the system tables to find the sysdatabases table. I want to create a dbml file for this database (so that I can use LINQ to retrieve all the user databases on the SQL Server). I've got around this by coding a class manually ... Is this possible? Thanks Griff Read More...
|
-
Hi there, I'm trying to do something exactly like what's described in Scott Guthrie's post here - in the section "Cleaning up the SupplierID and CategoryID Columns" Scott describes how to get the Supplier Name instead of showing the SupplierID - using the code in the GridView In my example, I have a table schools, and a table licenses. On the licenses table there is a school_id - which is a foreign key to the id key on the schools table. If I run the following Linq statement in LinqPad I get the Read More...
|
-
Hi friends, This week I started with programming in .NET and I found the real nice feature LINQ. This works pretty good but I have a question: Usually is get a single record with the following code: Code Snippet Target isthere = db.Targets.Single(t => t.emailaddress == "address@domain.nl" ); This works fine becouse I do this 'select' on een single column Primary key. But I have another table with a multi column PK (Table messageVersion with PK(messageID, language). How can I do a 'Select' on this Read More...
|
-
This is my query in Tsql : SELECT TOP 10 [ActionID], [ActionType], [ObjectID], MAX(date) FROM [dbo].[UserHistory] WHERE [EntityType] = 3 AND [UserID] = 1 GROUP BY [ActionID], [ActionType], [ObjectID], ORDER BY MAX(date) desc Following the other thread post about Linq group by multiple columns, I came up with the following linq query: var result = from i in (from uh in db.UserHistories where uh.User.UserID == UserID && uh.CRMEntityID == (int)entity select new { uh.ActionID, uh.ActionType, uh.ObjectID Read More...
|
-
The code below works, but it changes all rows to RED Forecolor. I guess I need a row index or something to tell it which row to change forecolor. This might not be the most efficent way to do this using LINQ ToList(). Anyone got some ideas or examples on how to change row color with a condition? Thanks for your help. var db = new dispatchDataContext (); var q = db.SP_DispatchHistoryLog(dispatch, casenum, streetname, officer); dataGridView1.DataSource = q.ToList(); foreach ( DataGridViewRow dr in Read More...
|
-
Hi I have a query like this: SELECT cp.pn_id, pn.pn_name, pt.pt_id, pt.pt_name, ps.ps_value,po.po_option,ps.ps_intvalue, ps_datevalue FROM ContentProperties cp inner join PropertyNames pn on cp.pn_id = pn.pn_id inner join PropertyTypes pt on pt.pt_id = pn.pt_id inner join PropertySelections ps on ps.ps_id = cp.ps_id left join PropertyOptions po on po.po_id = ps.po_id WHERE cp_type = 'DO' AND id = 40063 I found how to do the joins: var properties = from cp in dc.ContentProperties join pn in dc.PropertyNames Read More...
|
-
Hi, I have a large table that I query in vb.net with older code. I thought there would be a performance increase by converting it to LINQ, but I'm finding the opposite to be true. The LINQ query below is much slower then my sqldataadapter code (sometimes it even times out) and I'm not sure if it's my noob LINQ code or not. The table is VERY large, about 4.5 million records: Here is my older style working code that is MUCH faster then my LINQ code: Code Snippet MyCommand = New SqlDataAdapter( "select Read More...
|
-
Is there anyway to implement database transactions using XLINQ ? Read More...
|
-
Hi, I have a very simple question but i couldnt get answer yet on the reflection. How to retrieve entityset name from an objectquery? I have this datacontext which produces result as objectquery. What i want to know/get is the specific entityset name where my object was binded. I already retrieve the entity name but the specific entityset name i could not. Appreciate any help. Thanks Read More...
|
-
Hi, I'd like to know how to validate my deletes in the Business Layer rather than the UI layer, without having to edit my dbml file (because this could change over the course of the project and it's neater having custom code in a seperate file - like the way you can create a partial class and partial OnValidate event for inserts/updates) There is a technique described briefly here in Scott Guthrie's post under the sub heading "Custom Entity Insert/Update/Delete Method Validation", but it doesn't Read More...
|
-
Hi Rather than code all the classes for each table manually, it seems sensible to build these directly from the SQL Server's schema. I see in the VS 2008 IDE that one can simply do this by adding a "LINQ to SQL Classes" item and simply drag'n'drop the database tables that I'm interested in onto the designer and hey presto, all the code required for LINQ is created. However, the DBML files seem to be very database specific.... What I want is to use this designer to drag tables from my Development Read More...
|
-
How can I implement this in Vb.NET linq select daluid, attr1, attr2, attr3, attr4 from table1 minus select daluid, attr1, attr2, attr3, attr4 from table2 note that daluid is the PK using linq? I've already the dataset and datatables with same columns (maybe not same order) and all the records exists in both sides ( because I made a filter already) and I copied to a new datatable in memory now I just want the <> rows and eventually I also like to know just the attributes that are <> in a table like Read More...
|
-
One of the frequently asked questions is about the lifetime of a DataContext. Should it be a long-lived, application-scoped object or should it be a short-lived, request-scoped object? Let's get to the answer by considering the key parameters: DataContext is ideally suited for a "unit of work" approach : Retrieve a bunch of objects through one or more queries, make changes to the resulting object graph based on user input (databound to controls) or some other request and then call SubmitChanges(). Read More...
|
-
Hello all. Does anybody know how to get a scalar value from a stored procedure? For example, at the end of stored procedure I use next statement: SELECT SCOPE_IDENTITY() How can I get this value in my code? I try to use IExecuteResult result = this.ExecuteMethodCall(this, ((MethodInfo)(MethodInfo.GetCurrentMethod()))); but result.ReturnValue is 0. Is the using of output parameters the only way to do this? Thanks. Read More...
|
-
Hi, I have an xml file with entity references such as . I would like to read this xml to an XElement, and after processing data using LINQ, write it out to an xml file. Currently, entities get decoded (for example is decoded to space) when read with XMLTextReader and written to a file with XMLTextWriter. Is there are way to write entity references as it is into a file... Any advise would be appreciated, thanks. Following is a snip from the file I'm reading. http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd Read More...
|
-
Hi, What is the more performant way to know if a one-to-many relationship has 0 links? I have the feeling that calling Count==0 is not the best way because it would have to count each row and if there are many could be a poor solution. Would testing First on the collection be more appropriate? Thanks Nicolas Read More...
|
-
Hiya, I am working on a multi-part Blog about using LINQ to SQL along with WCF to feed data to Silverlight clients. Many people in the Silverlight forums are asking several questions about security, LINQ etc and I have run into a few things trying to discover some solutions. Btw my first 2 parts are available at my Blog: http://kellabyte.spaces.live.com I am hoping to get some solutions and respond to some Silverlight forums & post on my blog. Thanks in advance for any help! #1. I am showing how Read More...
|
-
Currently I have two queries to extract the neccessary information from the RSS feed, the first one retrieves the feed info and the second one gets the posts: Code Snippet var feedInfo = from channel in rss.Descendants("channel") select new { Title = channel.Element("title").Value, Link = channel.Element("link").Value }; var items = from item in rss.Descendants("item") select new { Title = item.Element("title").Value, Link = item.Element("link").Value }; Is there any way that I can use a single query Read More...
|
-
have an Table called say Customer ( it has a unique key contraint on Customer Name ) if I do ( with a non unique name ) Using db As New BlogsDataContext() db.Customers.InsertOnSubmit(aCustomer) db.SubmitChanges() End Using If I catch the exception and display a nice message, the user then changes the customer name to something unique, and saves using code above you get. "An attempt has been made to Attach or Add an entity that is not new, perhaps having been loaded from another DataContext. This Read More...
|
-
Is there a way to set the private variables of a generated class to [ DebuggerBrowsable ( DebuggerBrowsableState .Never)]? Read More...
|
-
Hello, I was trying the sql query below Grouping by more than one columns, but it gives syntax errors !!! Can somebody help me convert this query to LINQ ? select rl . UserID , rm . RewardType , sum ( rl . RewardPoints ) from rewardslog rl join rewardsmaster rm on rl . RewardID = rm . Id where rl . UserID = 'varsha' group by rm . RewardType , rl . UserID Thanks in advance Read More...
|
-
How do you rollback changes made to a table through a DataContext before you call the SubmitChanges? I tried placing the change into a TransactionScope but it did not seem to work.... Thanks Read More...
|
-
Hello All! I have generated several objects (via Linq) : Client - main table, ClientContacts - related table. I use next statement in stored procedure (for return client and its contacts): SELECT ClientID, ClientName FROM Clients WHERE ClientID = 1 SELECT * FROM Contacts WHERE FK_ClientID = 1 Could you please tell me if there is any possibility to get both Client and List with this procedure? Many thanks. Read More...
|
-
Hello All. I created Class Library and added a Link To SQL class. Then I added several tables from the Server Explorer, database Northwind. I wanted to configure my objects to use stored procedures. I clicked on any object and tried to select "Configure behavior" from the context menu but this command was disabled. Also the Default Methods in properties tab are also disabled. How can I resolve this problem? Many thanks! Read More...
|
-
Hi peeps I must be suffering from that rare stupidity based disease 'code blindness', because I can't figure out why the code below doesn't work. I'm trying to return specific records from a SQL table 'QuickLinks'. If I use the query below to select all, everything works fine: var query1 = ( from QuickLink lnk in datb.QuickLinks where lnk.LinkID == checkDataLink.LinkID select lnk).Single(); Now, if I use the 'select new' statement to specify what records I actually need, like so: var query = ( from Read More...
|
-
I've got a piece of code like the following: v ar query = from element in table where element.ISWHATIWANT == true orderby element.INDEX group element by element.INDEX into eg select new { INDEXSTR = eg.Key == "0" ? "Index 0" : eg.Key == "1" ? "Index 1" : eg.Key == "2" ? "Index 3" : "Index unknown", MYGROUP = from subelem in eg orderby subelem.MYDATE select new { DATE = subelem.MYDATE.ToShortDateString(), ... BLOB1 = subelem .IsNull("BLOB1") ? "-" : subelem.BLOB1 BLOB2 = subelem .IsNull("BLOB2") ? Read More...
|
-
Can I use LINQ to look for a number proceded by a key word. Given the following string "Make 3 in Model 7 in Denver". I would like to be able to create a Make Query to return the value 3 and a Model Query to return the value 7. I would also like to be able to create a query where a number is precedded by a word in a list. string [] wordlist = {"Make", "3", "in", "Model", "7", "In", "Denver" var make = from s in wordlist where s.isNum and s.previous in ("Make,"Mk") select s Read More...
|
-
Hey, i have a linq query to get all combinations of List List list1 = new List(); List list2 = new List(); var result = ( from a in this .list1 from b in this .list2 select new [] { a, b } ); This query gets all combinations in the form: object[][] Example (how it works now): List list1 = {o1 , o2} List list2 = {o3 , o4} The result is: object { {o1,o3} ; {o1,o4} ; {o2,o3} ; {o2,o4} } Now i want to change the two lists: List list1 = new List(); List list2 = new List(); i want that the result is still: Read More...
|
-
I've stumbled across a problem that I can't work out. I'm getting a 'Row not found or changed.' error when calling SubmitChanges when the row has definitely not changed. See sample code below. (I've stripped it down to the basic minimum.) Code Snippet using (_database = new CassiaDatabase(Global.GetConnectionString())) { TblQbCustomer Customer = (from tblQbCustomer in _database.TblQbCustomer where tblQbCustomer.ListID == item["ListID"] select tblQbCustomer).SingleOrDefault(); Customer.Name = item["Name"]; Read More...
|
-
Hi! So I've loaded some xml into an XDocument object. A portion of the xml looks like this: http://schemas.microsoft.com/aml/2001/core " xmlns:dt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882" xmlns:ve=" http://schemas.openxmlformats.org/markup-compatibility/2006 " xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:w10="urn:schemas-microsoft-com:office:word" xmlns:w=" http://schemas.microsoft.com/office/word/2003/wordml " xmlns:wx=" http://schemas.microsoft.com/office/word/2003/auxHint Read More...
|
-
I have a database with a core schema that is common to all implementations of my application. Individual implementations will then have additional tables, stored procedures, etc. which are bespoke to that implementation. What I am wondering is whether it is possible to create one set of LINQ to SQL classes for the core database objects (which would be referenced by all applications), and have a second set for the bespoke tables, which would be unique to each application. The second set would need Read More...
|
-
Some time ago, I was talking to some members of a team that used LINQ and LINQ to XML in one particular area of their code. They said that the code written using a conventional approach to XML was in the order of 6000 lines of code. When re-written using LINQ and LINQ to XML, it was around 800 lines of code. It was faster to code, and it was easier to debug. And there is some correlation between lines of code and bugs regardless of the type of code , so reducing lines of code means better software. Read More...
|
-
Hello everyone, i have spend some time on getting a like expression working in C# with linq. My goal is to build expression with the help of the expression tree. I searched this forum but didnt found anything usefull so far. example: to create: A => A.text == "Text" I use the following code snippet Code Snippet ParameterExpression entity = Expression .Parameter( typeof (TEntity), "entity" ); Expression ColumnExpr = Expression .Property(entity, Column); Expression ValueExpr = Expression .Constant( Read More...
|
-
I have an enumeration like this: Linq to XSD Alpha 0.2 creates me this: public sealed class UnitX_ { [DebuggerBrowsable(DebuggerBrowsableState.Never)] public static Microsoft.Xml.Schema.Linq.SimpleTypeValidator TypeDefinition = new Microsoft.Xml.Schema.Linq.AtomicSimpleTypeValidator(XmlSchemaType.GetBuiltInSimpleType(XmlTypeCode.String), new Microsoft.Xml.Schema.Linq.RestrictionFacets(((Microsoft.Xml.Schema.Linq.RestrictionFlags)(16)), new object[] { "s", "bp", "kDa", "nt", "Unknown", "Ã…"}, 0, 0, Read More...
|
-
Hello, I'm experimenting with using LINQ in a C# project, and have had a go with the O/R mapping of inheritance, OK it only implementes "single table inheritance" which is a bit disappointing but thats life, so I've implemented my data tables, as per the standard examples...and it works...fine....but what suprises me is that the subtypes don't appear in the datacontext as first class tables.....hmmm....not quite the OR mapping I was expecting....is there a (simple!) way to extend the datacontext Read More...
|
-
Hi, Can anyone tell me how to use LINQ in VS 2005. I have used system.data.DLINQ in my application but it doesnt work any way.. Kindly suggest me. Thanks ~vpatwal Read More...
|
-
Is there an easy way so that the mapped column of type string does NOT padded with spaces ? Thanks Read More...
|
-
For debugging and performance tuning reasons I wanted to output the SQL LINQ generates to ASP.NET's Page Trace. With help from a few other blog posts I was able to create a small TextWriter class that could be used for this purpose. Code Snippet using System; using System.Web; public class TraceTextWriter : System.IO.TextWriter { public override System.Text.Encoding Encoding { get { throw new NotImplementedException(); } } public override void WriteLine(string value) { HttpContext.Current.Trace.Write("LINQ", Read More...
|
-
What are best practices for dealing with a multithreaded application where backgorund workers need to perform tasks using Linq to Sql data contexts and the UI needs to databind against Linq to Sql objects and receive change notifications? I have tried an approach of putting a static event on my DataContext class and raising it inside of SubmitChanges so that other DataContexts that exist can subscribe to that event and then call Refresh on their tracked entities that may have changed. However, the Read More...
|
-
Okay, here's the situation. I'm trying to convert my old LINQ to SQL queries to ones that take into account which server the application is running on. If it's on one server, it will query a development database. If it's on another server, it will query a live database. The old queries look something like this: Code Snippet MyDataContext dc = new MyDataContext(); var query = from t in dc.table select t; foreach (var result in query) { //do stuff... } By default this was querying the live database. Read More...
|
-
I've got a connection to a Firebird Database. I've linked DataSources in the IDE. I've got all my 8 tables from which I can retrieve data. For each table, it was automatically created a DataTable object and a TableAdapter + a main TableAdapterManager. At the beginning of the code I fill tables through the command: TableAdapter1.Fill(DataTable1); TableAdapter2.Fill(DataTable2); TableAdapter3.Fill(DataTable3); TableAdapter4.Fill(DataTable4); ecc. Then I created a few LINQ queries that work perfectly Read More...
|
-
Once an item has been retrieved and added to the referential cache, is there any robust way of querying the cache to avoid a round-trip [assuming query on primary key etc]. I know it has been asked before ( example ), but looking at the log, and contrary to that post, it always seems to do a round-trip. I found an ugly hacky way of doing it (horrible, here ) but obviously this isn't a good idea... Read More...
|
-
Hi, I apologize if this has already been posted (couldn't find a post for it). I have two classes: Code Snippet public class A { pubilc virtual string MyString { get; set; } } pubilc class B : A { public override string MyString { get; set; } } I have an IEnumerable MyBs. When I issue the query: Code Snippet var x = MyBs.Where(b => b.MyString == "Foo") the MemberExpression's (i.e. b.MyString) Member (i.e. MyString) has its DeclaringType as A and not B. Is anyone getting this bevahior as well? Thanks Read More...
|
-
When I setup a database using LINQ to SQL, I have to update each stored procedure by adding Name="" to allow info to be returned. If I don't do this, a value of null is returned. If I update ( Move the items ) in *.dbml file, the *.designers.cs file is autogenerated again and I lose all the changes I made ( The Name=""s I added ). This is very frustrating. What do I need to do in order to fix this problem??? Read More...
|
-
It appears that LINQ to XSD requires that an XML document be loaded fully into memory before it can be "LINQ'd", i.e. a LINQ query against it can be enumerated. I'm not sure what the correct terminology for what I want to do is but basically I'd like to construct a LINQ query and have it run through all of the elements in an XML document using something like XmlReader. The point being, of course, not to have the overhead of holding the entire document in memory when I just want to make pass over Read More...
|
-
|
Hello All, i am struggling with building advanced linq queries on runtime. My main problem is, creating joins and where conditions at runtime. I am able to do the following at the moment. TEntity = instance of an linq entity TEntity.EntityTable = return the Table object of the Entity With the function CreateFilterExpression i can create an lambda expression which i can include into the where part. (Its based | |
|