|
|
May 2007 - Posts
-
I'm worried about the scaling of paging very large result sets with DLINQ current implementation of Skip() and Take(). The internal mapping of using the ROW_COUNT() function with a large (millions of rows) result set will eat huge amounts of resources. There is much more efficient way to do paging with a two step query and SET ROWCOUNT (for an example see http://www.4guysfromrolla.com/webtech/042606-1.shtml). Has something like this been considered as an alternative implemenation of Skip() and Take() Read More...
|
-
What is the best way to add some data integrity rules before data is saved/updated to the database. A simple example would be a table with a start and end date, and before the data is saved I want to make sure that the start date is on or before the end date, and if not return an error to the user before the data is saved. Can this be incorported to the LINQ code/model that is generated of do i just need to check the data myself before using SubmitChanges? Read More...
|
-
Suppose A database that supports three schemas: SA, SB and SC. Three tables TA, TB and TC located, respectively, in SA, SB and SC. Then, note that the SQL Metal tool will generate code with table classes named SA_TA, SB_TB and SC_TC. This makes for very ugly code and names that are too long. Is there anyway to get the tool to generate namesaces for schemas instead of the ugly underscoring behavior? Alternately, is the source code available for this tool? Alternately is there a comparable tool available Read More...
|
-
I have received a number of requests over a period of time asking how to get all the facets defined on simple types or complex types with simple content in an XML Schema. I recently wrote a code sample for the same and I thought i will post it for wider consumption. The code sample will handle restrictions on lists, unions as well as facets defined on base types. public static void GetSchemaTypeFacets(XmlSchemaType schemaType) { if (schemaType == null || schemaType.Datatype == null) { //Complex type Read More...
|
-
LINQ to SQL, possibly Microsoft’s first OR/M to actually ship in ten years of trying, was never even supposed to exist. It started out as a humble Visual Studio project on my desktop machine way back in the fall of 2003, long before anyone heard about it, long before anyone even guessed what would come next, except for the readers of this blog, of course, since I used to post often with long obtuse and sometimes psychedelic meanderings that with the proper one-time pad to decrypt it you might have Read More...
|
-
Hello I'm trying to implement a query provider for a generic (in-memory) collection library (ICollection<T>). The collections are Enumerable and thus Linq-queryable, but I would like to modify the expression trees of the queries to better exploit the capabilities of the underlying datastructures (ie. range queries can be executed quickly on a tree based data structure compared to examining each element in turn). I've gotten as far retrieving and poking around the expression trees, and I'm now Read More...
|
-
Hi NG, I know, this is not a "typical LINQ" question. In my case, I'm using the AdventureWorks Database with the following C# code. Code Snippet using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Sample0050 { class Program { static void Main(string[] args) { string connString = "Data Source=.;Initial Catalog=AdventureWorks;Integrated Security=True"; ProductDataContext prodDtcx = new ProductDataContext(connString); var query = from p Read More...
|
-
I am seeing something in CopyToDataTable that strikes me as a bit of a logic problem. First, calling: dataRow.Field< string >( "SomeColumn" , DataRowVersion .Original) when a field has no original value throws an exception. Calling AcceptChanges() on the DataTable that the DataRow is in causes a snapshot to occur of the original versions alleviating that problem. Of course when you call the AcceptChanges() method, the current version of each field becomes the original version, and Read More...
|
-
I just ingested a Schema using the a Linq to SQL DBML file in the designer. All looked good and seemed to be properly referenced. Then i tried to add a row to a lookup table like below: Code Snippet using (MyDataContext db = new MyDataContext(ConfigurationManager.ConnectionStrings["MyDB"].ConnectionString)) { track_status_enum x = new track_status_enum(); x.enum_value = TrackStatus.Archive.ToString(); x.track_status_id = (byte)TrackStatus.Archive; feed_item_comment_track f = null; db.track_status_enums.Add(x); Read More...
|
-
Hi, Hope this is the appropriate forum ... as a Linq newbie, trying out different things ... I will use tinyint as a foreign key in large tables ... and I find DLinq doesn't like it ... For reference I tried bigint and smallint as well, and there did not appear to be a problem with those data types. Code sample follows below. Hope this is helpful, Tony. Create a couple of tables with a little data ... Code Snippet create table tinyCust ( CustId tinyint identity primary key, CompanyName varchar(30), Read More...
|
-
If I have a windows applicaiton where the user can select one or more items from a list and if I create an array or colleciton of the IDs of the items selected how can I incorporate that into the LINQ Where clause? For example I can build a SQL statement of the items selected by the user to come up with the following: 'Dim Query = db.ExecuteQuery(Of audit_type) _ ' ("SELECT * From audit_type WHERE audit_type_id = 1 OR audit_type_id = 8") Is there a way to build a collection/array of the Read More...
|
-
I would like to generate file with content in "asp.net" style. got problems with something like <%@ Page Language="C#" %> <asp:Button ID="Button1" runat="server" Text='<%# "databind" %>' /> (just sample, not complete asp.net page) <%@ ... %> headers - do not know how to emit such content asp namespace prefix - it is easy and explained in xlinq overview. no problem biggest problem with attributes like Text='<%# "databind" Read More...
|
-
Hello, I have one question regarding LINQ inheritance. It is very common scenario to have some common columns that are used in all tables(objects), so it is very usefully to define some base object where this common columns are stored. Example: public abstract class EntityBase { int m_iID = 0; [Column(IsPrimaryKey = true )] public int ID { // ..Implentation } } [Table] public class Address : EntityBase { string m_strStreet = "" ; string m_strZIP = "" ; [Column] public string Street Read More...
|
-
I have an intermitent problem with Linq in Visual Studio "Orcas" beta 1. I have the following piece of code: Trade editTrade = ( from t in _db.Trades where t.Serial == serial select t).FirstOrDefault(); if (editTrade != null ) { editTrade.DateChecked = DateTime .Now; editTrade.CheckedBy = GetUserName(); _db.SubmitChanges(); } Depending on the record I will get a System.Data.Linq.ChangeConflictException stating that the row changed or didn't exist. I can't see anything hapenning in the database Read More...
|
-
Hello! I wrote a code for building a tree over records in a database table. I used Linq to SQL. The execution of this code under Visual Studio Orcas took 40 sec (for 100 000 records). I executed the same code (of course I changed the namespaces and some of the method names of the Linq code) under Visual Studio 2005 and it took 15 sec (for 100 000 records). I ran the SQL Profiler and I was surprised to see that the queries from the VS Orcas code were executed much slower than the queries from the Read More...
|
-
Hi, I'm building a custom installation wizard for an application I've written in c# 3.0 / LINQ. Which .NET file(s) do I have to include in the installation package to enable the user to run the program? Thanks. Read More...
|
-
Hi to all, im using dlinq and im experienced with some other persistency frameworks. Now i detected some problems in my projects (how can i solve those problems?): 1) To show up a save-dialog i have to ask a object if it has changes like Customers.HasChanges But there is no property like this 2) I only want to save a child object and not the complete tree so there is no Object.Save for a single object 3) I cant see my own new objects in the object list for example a customer has some orders. Now Read More...
|
-
Hi to all, im using dlinq and im experienced with some other persistency frameworks. Now i detected some problems in my projects (how can i solve those problems?): 1) To show up a save-dialog i have to ask a object if it has changes like Customers.HasChanges But there is no property like this 2) I only want to save a child object and not the complete tree so there is no Object.Save for a single object 3) I cant see my own new objects in the object list for example a customer has some orders. Now Read More...
|
-
Hi NG, I'm studying following code: Code Snippet var q = from s in db.Suppliers join c in db.Customers on s.City equals c.City into scusts select new { s, scusts }; Why must I use "into scusts" code part or why can I not use "select new {s, c}"? Thx for explanation Ozgur Aytekin Read More...
|
-
Hello, First, sorry for the poor title of the post - didn't know what else to put :) On to my problem. I have a table which contains two primary keys, ID and LatestRevision. This then links onto another table which also has a ID, Revision, Title, Modified, Body. I wanted to do a join for the latest version of the document, based on the contents of the first table, so in SQL I would have done something like : SELECT * FROM DocumentList d INNER JOIN DocumentRevision dr ON d.DocumentID = dr.DocumentID Read More...
|
-
Another adventure in LINQ land... Have a table Test (TestID int NOT NULL IDENTITY, Name varchar(50)) and a Test class created with the designer. Trying to insert a new object with a stored procedure. The problem is how to get the TestID field populated (Name field works fine) on a test object. Code Snippet ALTER PROCEDURE dbo.AddTest ( @name varchar (50) ) AS INSERT INTO dbo.Test ( Name ) VALUES (@name) RETURN SCOPE_IDENTITY() This adds the row to the database, but leaves the TestID field 0 on the Read More...
|
-
Hello, So I'm looking at LINQ again and I have come to a bit of a problem. I have a set of tables, which I want to return as a single custom entity for use within my application. I heard that by using Table Valued Functions, you can still have Linq pass work to SQL Server for processing - such as ORDER BY, SKIP and TAKE without having to do it in memory, unlike stored procedures. So I created my Table Valued function which returned a SQL SELECT statement as a table. Within the Linq to SQL designer Read More...
|
-
Hi NG, I'm using the following statemtn to get a record from my database Code Snippet var productItem = productDtcx.Product.Single(p => p.ProductNumber == "TP00002" ); In case, when this record is not existing in my database I'm receiving the following exception: Code Snippet System.InvalidOperationException was unhandled Message="Sequence contains no elements" Source="System.Core" StackTrace: at System.Linq.Enumerable.Single[TSource](IEnumerable`1 source) at System.Data.Linq.SqlClient.SqlProvider.SqlQueryResults`1.PostProcess(Expression Read More...
|
-
My Order table contains an OrderTypeID (int) field in the database. The OrderTypeIDs correspond to defined C# enum types (ie. OrderType.Internal). Using a partial class I can extend the LINQ to SQL Designer generated Order class to contain a OrderType property which returns a OrderType value instead of an int value. If I use the property in a query var orderList = from order in CurrentDataContext.Orders where order.OrderType == OrderType.Internal select order; I get an exeption Binding error : Member Read More...
|
-
Hi All, I'm new to this forum so sorry if I'm repeating a question answered earlier - I did a search and found nothing that seemed relevant. I am producing a LINQ query provider using the May '06 CTP. The query class targets the SPARQL query language from the W3C. I have also produced another working query provider from which I took code for the current QP, but I am running into problems with Queryable.Where. Here's what the unit test looks like: [TestMethod] public void SparqlQuery() { string urlToRemoteSparqlEndpoint Read More...
|
-
I just started to play with ORCAS, and already liked it. I made a dbml object with a Stored procedure that has 1 Parameter. Orcas made a nice Designer class that I don't understant yet all of them, but there is a Class with my stored procedure name as following: public partial class MyStoredProcedure: global::System.Data.Linq.INotifyPropertyChanging, global::System.ComponentModel.INotifyPropertyChanged with all fields returned by SP as properties. I have spent few hours to look for a sample to how Read More...
|
-
Hello! I have an ASP.NET app. where I use DLINQ. I want to find out the best way of using DataContext because perfomance is a critical thing. I have these variants: 1) DataContext will be initialized only once and placed into the Session. (But my DB structure is quite big) 2) DataContext will be initialized every time when a query executes. 3)... Please tell me your suggestions. Read More...
|
-
I want to do a query on a csproj file : Code Snippet from c in XElement.Load(csprojFile).Elements("ItemGroup").Elements("Compile") select (string)c.Attribute("Include"); But I have no element when I execute my query. When I remove in csproj file xmlns=" http://schemas.microsoft.com/developer/msbuild/2003 " I have some elements when I execute my query. Why and what I must change for do not have to change csproj file? Read More...
|
-
In May CTP there has been QueryExpression class that allows to create where expressions from strings. In orcas beta1 there is no QueryExpression, nor I can find it equivalent In orcas beta1 linq samples there is DynamicExpressions sample witch defines System.Linq.Dynamic. And it seems quite nice :O) But it is not in bcl – it is only sample. Anyone knows where has QueryExpression gone ? Or in beta2 there will be System.Linq.Dynamic in bcl ? Read More...
|
-
Hi, Didn't see any threads on the topic, so I'd just like to point out that DLinq designer generated classes treat computed columns as normal columns, making updates fail, since DLinq tries to update the columns. Setting IsDBGenerated=true in the Column attribute solves the issue, but I would rather have the designer do that for me. Anyways, kudos to the LINQ team for a magnificent addition to C#!!! Read More...
|
-
I thought some of you folks might find this useful. I know everyone loves using the static factory methods on Expression to create expression trees programatically. And, of course, we know expressions are immutable, which prevents us from writing a template tree from which we can make changes and rip copies. To help with problems in this class, I wrote something I am calling "MetaLinq", which includes two cool features: A set of classes (EditableExpression and it's children) for creating Read More...
|
-
hi, SQL metal bails out if i run it to output to a readonly file under source control. i have the command integrated with VS via the external tools. i understand why it happens, but it would be a nice feature if the file could be checked out automatically if the solution is open. in the meantime, my script is set up to delete the target source file which works ok. tim. Read More...
|
-
Hi, I have not used LINQ, just heard some about it. I have an older app that I maintain, written in the VS 6 days using MFC, I use VS 2005. My latest maintencance project is to add some XML ability to the app. So my question is can I use LINQ to do this? If so, are there examples anywhere? Thanks Jeff Read More...
|
-
Hello I'm a little confused why the entities generated by SqlMetal / VS Orcas Entity Designer implement interfaces that reside in two different namespaces (System.ComponentModel and System.Data.Linq). Not sure why the design is like this, but I strongly suggest getting rid of the duplicate System.Data.Linq.INotifyPropertyChanging. Current: Code Snippet public partial class Page : System.Data.Linq.INotifyPropertyChanging, System.ComponentModel.INotifyPropertyChanged Should be: Code Snippet public Read More...
|
-
I have a pretty simply xml file which I'm loading in XLinq. After I have the data loaded how do I do a query on it? For instance, I want a subset of the records where a certain attribute is a certain value. And I want the data sorted by another attribute value. Code Snippet string uri = AppDomain.CurrentDomain.BaseDirectory + "PagePlugins.xml"; XElement pagePlugins = XElement.Load(uri); Console.Write(pagePlugins); IEnumerable page1Plugins = from c in pagePlugins where (int)c.Element("pagePlugin").Attribute("pageId") Read More...
|
-
Hi, I have 2 projects using Linq and in both projects I'm having the following problem : I have an object that has a reference to a parent object. At a certain point I create a new object and assign the parent object to the property in the newly created object. When I do DB. submitchanges LINQ To SQL also tries to insert the parent object, where it should only put it's id in the newly created object. This fails of course due to primary key violation. I have this on 1 to many and many to many situations. Read More...
|
-
Hi NG, I'm using the AdventureWorks Sample Database for my "simple" LINQ Application. I defined the following statement: Code Snippet 10 Table<Product> Products = dctx.GetTable<Product>(); 20 Table<ProductCostHistory> ProductCostHistories = dctx.GetTable<ProductCostHistory>(); 30 var prods = from p in Products 40 where p.ProductCategories.Where(prodCostHist => prodCostHist.EndDate == null) 50 select p; Each time, when I want to compile my application, compiler Read More...
|
-
Hello I just installed the Orcas beta and am playing with my first samples. I am unable to compile this line var numbers = Sequence.Range(1, 9); I get "The name 'Sequence' does not exist in the current context' Can anyone tell me where Sequence is defined? Thanks Patrick Read More...
|
-
Hi, I need to query my sql database by a name field. In T-SQL I would use "where name like '%name1%name2%nameN%'". With DLINQ I was thinking about using something like string [] names = new string []{ "Jonh" , "Trico" , "Pir" }; var res = from a in db.Membros select a; foreach ( string var1 in names) { res = from a in res where a.Nome.Contains(var1) select a; } Unfortunally this do not trow the same results as: var res = from a in db.Membros where a.Nome.Contains(names[0]) Read More...
|
-
Help please Linq to SQL Database is = Northwind DataContext = new DataContext(); Customer entity class Table<Customer> Customers = db.GetTable<Customer>(); Customer cust1 = new Customer(); cust1.CustomerId = “a1111”; cust1.City = “LONDON”; Customers.Add(cust1); This does not add a item/record/row in Customers collection. Instead db.GetChangeText() gets or holding the insert statement for this newly added item. If a run a LINQ query it gives me only those items/rows which was extracted Read More...
|
-
I have two questions about the code generated by Linq for SQL in VS Orcas Beta 1: Linq for SQL generates Set-Property which looks like set { if (( this ._Name != value )) { this .OnPropertyChanging( "Name" ); this ._Name = value ; this .OnPropertyChanged( "Name" ); } and a the following event publisher protected void OnPropertyChanging( string propertyName) { if (( this .PropertyChanging != null )) { this .PropertyChanging( this , new global ::System.ComponentModel. PropertyChangedEventArgs Read More...
|
-
I am running a windows app that is trying to insert multiple items into a table using the following code: Dim db As New CastleDataClassesDataContext(Standard.MasterConnectionString) Using (db) For i As Integer = 1 To MenuIDsToSave.Count Dim role As New application_role_menu role.application_role_id = ApplicationRoleID role.application_menu_id = MenuIDsToSave(i) role.last_update_id = Standard.UpdateUserID role.last_update_datetime = Now db.application_role_menus.Add(role) Next db.SubmitChanges() End Read More...
|
-
what's the difference between Enumerable.Select() and Enumerable.TakeWhile()??? I read MSDN, but i can't quit clear. Another Quesiton: How can i return specified number of elements in LINQ? The following is my way, but i think maybe have better ones. Method 1. int[] list = new int[]{1,2,3,4,5,6,7,8,9,0,10,23,21,56,78,999}; int _index = 0; var query = from i in list where i > 5 order by i descending let index = _index++ where index < 2 select i; Method 2. int[] list = new int[]{1,2,3,4,5,6,7,8,9,0,10,23,21,56,78,999}; Read More...
|
-
Hey gang. I was reading an XLINQ tutorial and it mentioned how to parse RSS via XLINQ and one of the first lines was loading the url. Unfortunately I get exceptions when I try and do the following in a Web Service: XElement.Load(url); or XDocument.Load(url); Can these only do file based uri's and not HTTP? Perhaps the tutorial had an error? Thanks and take care. Read More...
|
-
I've come across an interesting problem during my LINQ to SQL analysis.. I'd like to save a single user record in a Session variable for use throughout my web app ie: Session["CurrentUser"] = context.Users.Single(user => user.UserID == 1); On a different .aspx, when updating a company record (company has a one-to-one relationship back to user) as below: var c = context.Companies.Single(co => co.CompanyID == 1); c.CompanyName = "A different name"; c.CompanyDesc = ""; Read More...
|
-
Hi, Since I am targeting SQL Server 2005 for release shouldn't I also develop with SQL Server 2005? Thanks, Mark Read More...
|
-
I'm using May CTP. I'm trying to access the data in a StoredProcedureMultipleResult object. I can access First() without any problem, but I really want to call ToArray() or ToList(). Both methods error. Here's a sample: // Call the stored procedure System.Data.DLinq. StoredProcedureMultipleResult result = db.SmartSearch(org,address,zip,phone,email); // This works SmartSearchResult add = result.GetResults< SmartSearchResult >().First(); Console .WriteLine(add.Address); Console .WriteLine(add.City); Read More...
|
-
I have tables: Sport ID (PK) Name Team ID (PK) SportID (FK) Name The database mappings are created with the Orcas Beta 1 LINQ to SQL Designer. Sample code: var sportList = from s in dc.Sports where s.ID == 1 select s; Sport sport = sportList.First(); Team team1 = new Team(); team1.Sport = sport; team1.Name = "foo1"; Team team2 = new Team(); team2.Sport = sport; team2.Name = "foo2"; dc.Teams.Add(team2); dc.SubmitChanges(); // This throws NullReferenceException because team foo1 Read More...
|
-
This LINQ bug is almost as awful as the rich text editor on this forum... Anyways..... I have two tables in a database. One of them, when I update values and call SubmitChanges, is fine. The updates go to the DB. The other, nothing happens. And the code for them is very similar. It takes the form below. This is straight-up bad: TestMetal.TestContext db = new TestMetal.TestContext(...); var T1 = (from l in db.Test1 where l.Name=="test str" select l).First(); var T2 = (from f in db.Test2 Read More...
|
-
I am trying to store serializable objects in the database using Linq to Sql. I have created a binary field in the table. When I drop the table on the designer it creates a byte array as the property type. Then I use BinaryFormatter to Serialize and Deserialize from this byte array. It is working, but I have noticed that I can also set the property as an object in the designer. When I set the property as object it throws an exception. Is there any simple way to store an .net object into database using Read More...
|
-
I am a little confused , here it is: Database: UserTable UserID (PK) AgeRangeID(FK) AgeTable AgeRangeID(PK) AgeRange (string) "18-24","24-35".... AgeTable is already populated and should not be changed. Code Snippet DataContext dc = new DataContext(); dc.GetAllAgeRanges(); // returns content of table AgeTable UserTable user = new UserTable(); user.AgeRange = dc[0]; // you would think that this just link the 2 dc.Users.Add(user); dc.SubmitChanges(); the above code, creates a new Read More...
|
-
I have a DataGridControl bound to an EntitySet like this: Code Snippet <Window.Resources> <ObjectDataProvider x:Key="mforder" /> </Window.Resources> ...<more XAML here>... <xcdg:DataGridControl x:Name="notesdatagrid" Grid.Row="1" Grid.Column="1" CellEditorDisplayConditions="MouseOverCell" EditTriggers="BeginEditCommand,ActivationGesture" ItemScrollingBehavior="Immediate" DataContext="{Binding Source={StaticResource Read More...
|
-
not sure what is going on here is my code : Public Class Form1 Private Sub Form1_Load( ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase .Load Dim Name As List( Of People) Name = New List( Of People) { _ {ID := 1, IDRole := 1, LastName := "Anderson" , FirstName := "Brad" }, _ {ID := 2, IDRole := 2, LastName := "Gray" , Firstname := "Tom" } _ } Dim query = From p In Name _ Where p.ID = 1 _ Select p End Sub End Class Read More...
|
-
Hi I'm a student from switzerland working on a project about using Linq in a 3 tier architecture. My entity graph is: A category has got many subcategories which has got many Products. I built that using the in the Orcas Beta 1 included tool for Linq To SQL. The Server gets the object using Linq and sends them to the client using WCF. I wrote a Generic WCF Service which is implemented for the types I want to get from the server to the client. My current problem is that can't deserialize the object Read More...
|
-
I have a simple problem with datatemplate. What I try to do is: read xml file, create new XmlDataProvider, add new TabItem in TabControl with datatemplate inside, (datatamplate contain ListBox) fill ListBox in created TabItem with data from xml file. It working without datatemplate only. Xml file example (D:\\file.xml): Code Snippet <Features Name="FeaturesTest" number="94" > <Feature index="148" name="attribute1" > <FeatureData> -214, -139 Read More...
|
-
Hello , Is it possible to create a System.Expression.Expression<T> Object which contains a lambda Statement body. I simple tried with this code - Expression<Func<int, int>> expr = {Console.WriteLine(x); return x;} It simply refuse to work. I think there must be some other way to create such an expression. Please guide me. Thanks Pankaj Read More...
|
-
Just curious, how is the database connection in LINQ? Is it remain the same as existing way, or there are special or easier method for performing a database connection? Besides that, LINQ is a integrated query that we can use database commands in the programming language. So, can it perform statements like updates, delete others than retrieval? TQ Read More...
|
-
Question one: I'm wondering why SqlMetal changes the capitalization of table names? The database has "aa_Services", but it comes out "Aa_Services" in the generated class. I don't see a documented switch to control this behavior. This is something you can get used to I suppose, once you're aware of it. Still, it's odd when you've been used to using the lowercase name in code. Question two: With a table name of "OnlineStatus", why does the class become "OnlineStatu" Read More...
| |
|