|
|
November 2007 - Posts
-
LINQKit v1.0 is now available for download . LINQKit is a free set of LINQ extensions, aimed primarily at LINQ to SQL. It comprises the following: An updated and extensible implementation of AsExpandable() , based on Tomas Petricek's earlier work A public expression visitor base class ( ExpressionVisitor ) PredicateBuilder With LINQKit, you can: Plug expressions into EntitySet s Use expression variables in subqueries Combine expressions (have one expression call another) Dynamically build query predicates Read More...
|
-
I have a WCF service that have these methods; public PersonalInfo GetPersonalInfo( int userId) { return db.PersonalInfos.SingleOrDefault(p => p.UserId == userId); } public void UpdatePersonalInfo1( PersonalInfo personalInfo) { db.PersonalInfos.Attach(personalInfo); db.SubmitChanges(); } public void UpdatePersonalInfo2( PersonalInfo personalInfo) { PersonalInfo old = db.PersonalInfos.SingleOrDefault(p => p.UserId == personalInfo.UserId); db.PersonalInfos.Attach(personalInfo,old); db.SubmitChanges(); Read More...
|
-
Hello, In my app I create a new instance of my DataContext object (created using Linq to SQL) and then do some querying etc using it. Whilst doing this, I call a custom function that I wrote for one of the tables also created using Linq to SQL. Inside this function, I need a reference to a DataContext. Do I: 1. Create a new DataContext within the function? 2. Pass in the existing DataContext as a parameter? If you create a new DataContext when one already exists, what happens? I want to reuse the Read More...
|
-
Hello, Can anyone point me in the direction of some official Linq RTM documentation or examples on producing dynamic linq queries at runtime ? I have scoured the internet for a couple of days and I only seem to be able to find Beta documentation or examples that don't work with VS2008 RTM. I've also read about an official Linq dynamic query sample, but I can't find it anywhere.: Basically I want to create a dynamic Linq query at runtime using either: 1. Strings (a bit like creating a SQL query) 2. Read More...
|
-
Hello, I am trying to create dynamic Linq queries at runtime. I already have a Linq to SQL datacontext, and the chances are that the data my dynamic query will return has already been returned by a normal Linq query before, and is therefore already locally cached. My question is: If I create a dynamic Linq query at runtime, will Linq be clever enough to retrieve the results from the local Linq cache if they are in there, or will Linq always retrieve the results directly from the database? Many thanks, Read More...
|
-
Hi, I am trying to rollback some inserts in part of my code (before calling SubmitChanges). However, after I rollback a transaction, db.GetChangeSet().Inserts is not cleared. Consider the following: Code Block db.Transaction = db.Connection.BeginTransaction(); // Add some entities db.Transaction.Rollback(); foreach ( var change in db.GetChangeSet().Inserts) MessageBox .Show(change.ToString()); The last 2 lines: foreach ( var change in db.GetChangeSet().Inserts) MessageBox .Show(change.ToString()); Read More...
|
-
I'm using VS2008 RTM Pro. I have a SQL table named LibraryFiles and am working on a WCF service. In the Service, I've added a LINQ to SQL Classes Item, then added the LibraryFile object to the diagram. (Very nice). Now I want to return an IEnumerable from a WCF method. At first I was getting this error: Type 'MPG.LibraryFile' cannot be serialized. Consider marking it with the DataContractAttribute attribute, and marking all of its members you want serialized with the DataMemberAttribute attribute. Read More...
|
-
Can someone kindly tell me where the (new) Sqlmetal is hidden in VS RTM (Pro)? Thanks, Casey Read More...
|
-
Hello, I am currently building an xml file using data that im loading from a SQL Sever 2005 database. I am currently loading the data using a SQLConnection, and loading the fields I want into a string variable named proText. Then using this string, i split it up into columns, and create the XML file. I was curious as to if this is a good way of doing it, or if there was a way to use LINQ to create the XML file directly from the Database fields. Thanks, Steve Read More...
|
-
http://forums.microsoft.com/MSDN/ShowForum.aspx?ForumID=1986&SiteID=1 Read More...
|
-
I'm coming from a typed dataset ADO.net background so I'm used to being able to call a getchanges on a table and just submit those results and similarly being able to revert user changes before they are committed was also a very intuitive and powerful feature. Are those features missing from linq to sql? Read More...
|
-
I'm wondering if I've missed something in the way AggregateException works - it seems excessively awkward. For instance, suppose I want to catch an IndexOutOfRangeException, and do the following: try { Parallel.Do ( () => { throw new IndexOutOfRangeException(); } ); } catch (AggregateException ex) { if (ex.InnerExceptions.OfType().Any ()) { // This never fires } else throw; } The highlighted code never actually runs, because ex contains a nested AggregateException (which in turn, contains the IndexOutOfRangeException). Read More...
|
-
Hey, I'm trying to get a subset of the rows in a table based on a list of ids that I have, using LINQ to SQL. Something like: List fooIdList; //This might have 1000s of Ids in it. List filteredFooList = myDataContext.Foo.Where(foo => fooIdList.Contains(foo.FooId)).ToList(); The problem is, the id list might have many thousands of ids in it -- this causes an exception to be thrown which, to my understanding, is because SQL Server doesn't allow more than 2100 parameters. Is there any way to get this Read More...
|
-
hi all. untill today, we used dataset for data quering. when we had a datatable and we wanted to filter it, we used dataview.rowfilter="...' but this method is not the performance method. so, now after i'v introduced to linq to dataset, i was wondering, will using linq give me better performance? Read More...
|
-
MSDN Parallel Computing Development Center: http://msdnlive.dns.microsoft.com/en-us/concurrency/default.aspx Parallel Extensions, Dec 2007 CTP: http://www.microsoft.com/downloads/details.aspx?FamilyID=e848dc1d-5be3-4941-8705-024bc7f180ba&displaylang=en Read More...
|
-
Hi! What about LINQ to Oracle? Can I download it somewhere? Thanks. Read More...
|
-
Hi All, I'm now using Visual C# 2008 Express Edition to make some test on LINQ. I've got a dbml file generated from the Northwind database with two tables "Order" and "Order_Detail", and I tried to select one order from the parent table and show the related "OrderDetails" to the child View. The strange thing is, if I do the query like this: NorthWindDataDataContext db= new NorthWindDataDataContext(); Order o1 = db.Orders.Single(o => o.OrderID == 1); var details = from d in o1.Order_Details select Read More...
|
-
Hi guys, I failed a problem today when using the LINQ to SQL generated code to call a stored procedure that has a numeric output parameter and uniqueidentifier input parameter . For example, I have this sproc: -- ============================================= -- Author: Sergey Ryabushenko -- Create date: 2007-11-13 09:34:28.733 -- Description: This procedure returns all users groups of this department and all children departments -- Parameters: @InstitutionId - uniqueidentifier the unique identifier Read More...
|
-
After upgrading to RTM, I am getting exceptions when trying to update a disconnected object. This code was previously working in Beta 2 Code Block public static void UpdateEmployee(Employee employee) { using (HR DataContext dataContext = new HR DataContext ()) { //Get original employee Employee originalEmployee = dataContext.Employees.Single(e=>e.EmployeeId==employee.EmployeeId); //attach to datacontext dataContext.Employees.Attach(employee, originalEmployee); //save changes dataContext.SubmitChanges(); Read More...
|
-
Hi all, I'm trying to test the LINQ in VS2008, but I stopped in what appear a simple problem/solution, I'm trying to just insert a new record in the DB or delete an existing one. here is the code after the the linq mappping: Code Block DatabaseClassesDataContext dc = new DatabaseClassesDataContext(); //to see the sql statements dc.Log = Console.Out; Customer c = new Customer(); c.Name = "bla bla"; //just this field, the PrimaryKey is Identity dc.Customers.InsertOnSubmit(c); dc.SubmitChanges(); I'm Read More...
|
-
I'm trying to figure out how to return and update Symmetric Key encrypted SQL columns. I'm trying to use a LinqDataSource with a FormView control. I'm sure it will probably end up being like it always is with databound controls -- there is that one small thing that makes it not work, unless it is a simple data example. I have Stored Procs that open the key and Select, Insert and Update the table. I tried using the LINQ to SQL class with Stored Procs, but there is no way to specify a SP for the Select Read More...
|
-
Hello, I want to generate with LINQ To SQL designer an entity public but with a private constructor. In fact, I want to make a factory on the partial class. How can I do this? I see that I can change access on a class but I don't see it for constructor (of course, I don't want to modify generated code). Read More...
|
-
Hi,guys! Pleasr excuse me. I want to ask you. I have SP : _______________________________________________ set ANSI_NULLS ON set QUOTED_IDENTIFIER ON GO -- ============================================= -- Author: Sergey Ryabushenko -- Create date: 2007-11-13 09:34:28.733 -- Description: This procedure returns all users groups of this department and all children departments -- Parameters: @InstitutionId - uniqueidentifier the unique identifier of department -- @DepthRecursive - Depth of recurcive -- Read More...
|
-
Using the VS2008 RTM, and SQL 2005 I got the following error when I tried to add a row where the Primary Key column was of TinyInt. I was amused by the statement, since there were already 4 rows in the table that the server very happily generated the value and added. ==================================== System.NotSupportedException was unhandled Message="The primary key column of type 'TinyInt' cannot be generated by the server. " Source="System.Data.Linq" StackTrace: at System.Data.Linq.SqlClient.QueryConverter.GetIdentityExpression(MetaDataMember Read More...
|
-
Hi, I was writing a little sample app last night to experiment with LINQ To SQL. Say I have a (very simple) table with the following structure: ContactId FirstName LastName Age I am loading the data into memory using the following code: private List Contact > GetData() { using ( TestDataDataContext context = new TestDataDataContext ()) { var q = from c in context.Contacts select c; return q.ToList Contact >(); } } Now let's say that sometime later in my program, I want to refresh one of the contacts. Read More...
|
-
Hi. I like the vs2008 linq to sql data classes and the way you can use the designer to add properties to a class that represents you data tables columns etc. Is it possible to add additional member properties, for example a description field for the column and have it displayed along with the other column member properties in the designer? I have looked at the ColumnAttribute class but it is sealed. Am I way off track or is this a possibility and if so how? King regards Read More...
|
-
Is there a simple way to display data from another table (connected with foreign key relationship), without adding extra properties to the OR model? Suppose I have a table like Product in Northwind with a CategoryID field and a related Category table with CategoryID and CategoryName. I would like to have a DataGridView on a Windows Form with list of Products and display CategoryName (instead of CategoryID) as a simple TextBoxColumn. It can apparently be done very simply in ASP by changing boundColumn Read More...
|
-
Hi I've been designing a couple of application using NHibernate and now looking into linq. I must mention that I am doing this at my spare time, I am not a proffessional developer, nor is my command over the english language. The way I've been using NHibernate as an translator between my business objects and the data tables in the database. Basically it can be seen in this example.. class A { public string C; public string D; public IList E; } class B { public string A; public string C; } It takes Read More...
|
-
Any word on whether many-to-many will ever be supported in LINQ to SQL? Or does one have to use LINQ to Entities for this? If so, any word on when LINQ to Entities will be released? Having used other ORMs such as N/Hibernate and Java Persistence, there is something about LINQ to SQLs lack of many-to-many support that really rubs me the wrong way. Does anyone know if it's possible to return LINQ objects from web service methods? I'm guessing the proper way to do it is to use a separate data model Read More...
|
-
Hello, I have a table Versions: - Id uniqueidentifier (PK) - Name nvarchar(30) (NOT NULL) - OldVersion uniqueidentifier (allow NULL) I have a relation between OldVersion and Id With Linq To SQL designer, I want to have a relation one to one. When I do this on property grid in designer, the code generated by designer does not compile. Indeed, it is: Code Block [Association(Name="Version_Version", Storage="_Versions", ThisKey="Version1", OtherKey="OldVersion", IsUnique=true, IsForeignKey=false)] public Read More...
|
-
Hi, I am just wondering if there is a roll back in LINQ if there is any exception occurs? If so, could u show me an example? Thanks a million.! Read More...
|
-
Hello, I have a problem when inserting new recorded using LINQ. How I have a datatable Store ( [StoreID] int (auto-increment), [StoreName] nvarchar(150), [DateCreated] datetime (getDate() by default) ) My code is StoreDateaContext db = new StoreDataContext(); Store newStore = new Store(); newStore.Storename = "test"; newStore.DateCreate = ????? I have already set DateCreated = getDate() by default in db. theoratically, I dont have to assign the value to DateCreated since it should be done when I Read More...
|
-
I got VS2008 RTM and decided to try out LINQ, and I was a little disappointed with the performance in my initial tests. The insert performance of my current application is the worst bottleneck, so I created a test to insert 60000 records into a SQL Server 2005 table. Each record has about 40 fields, and about half of those are strings. Here are the results: 1) LINQ to SQL, all code created through the designer. Uses AttributeMappingSource(). Runs in 93 seconds. 2) LINQ to SQL, manually created instance Read More...
|
-
Hi, I just got VS2008 RTM and wanted to give Linq a try and wrote a small test app that loads a fairly large XML (~70MB) with 200k items (further referenced as "Options") of interest. I built the following query which extracts all the items I need and groups them: Code Block var classes = from secdef in doc.Descendants( "SecDef" ) where secdef.Element( "Instrmt" ).Attribute( "CFI" ).Value[0] == 'O' && (secdef.Element( "Instrmt" ).Attribute( "CFI" ).Value[3] == 'S' || secdef.Element( "Instrmt" ).Attribute( Read More...
|
-
When using LinqDataSource.Where (that is a string), I noticed you can use apparently a SQL like language that is parsed by LINQ to finally be translated into the appropriate SQL for the underlying provider. I found in particular here or there : - the GUID(string) function - the DATETIME(year,month,day) function Using LIKE doesn't seems to work. What is the notation for this ? More generally is this documented somewhere ? It would be very usefull when one want to use the LinqDataSource.Where property... Read More...
|
-
I cannot get SqlCe 3.5 get to use TransactionScope correctly when also using linq. Basically I want to use TransactionScop to control rollback the SubmitChanges into SqlCe.Even though the final 3.5 RTM Version of SQLCe is said to support TransactionScope it does not seem to do it at least not when using Linq to do the inserts. The standard way of manual transactions work fine. I tried just about all permutations of ordering and arguments but the below code should not commit anything to db as far Read More...
|
-
What used to work in pre BETA 2/RTM does not work anymore. When accessing an EntitySet's Count property i get this: Explicit construction of entity type 'SmartFile.Data.FileData' in query is not allowed. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.NotSupportedException: Explicit construction of entity type 'SmartFile.Data.FileData' Read More...
|
-
Can anyone help me with these two simple things: 1) Have the dbml always reference the connection string defined in my settings config file. ie. I *do not* want the connection string copied over to the dbml file. This is because connection strings change between prod and test. I know about not having a default constructor and passing the connection string in the constructor but the above method with a default constructor and the connection string being picked up automatically is easier. 2) When I Read More...
|
-
Hi all, if I have an ID in Request.QueryString["ID"], what is the correct way to check if this ID already exists in LINQ and the Entity Framework? I would like to write code like this: DataClassesDataContext dc = new DataClassesDataContext(); if (dc.Customers.Exists(ID)) { } or if (dc.Customers.Contains(ID)) { } or something like that. What do the experts say? Read More...
|
-
I am, trying to build a function with a list of countries but I am getting nowhere. Stepping through the code the data is returned from the database but by the time it hits return the list is empty. Could anyone tell me where I am going wrong? Thanks Public Function GetCountries() As List(Of Country) Dim ret = From c In Me.Countries Select c _ Where c.show = True _ Order By c.countryName Return ret.ToList End Function Read More...
|
-
I have the following xml that i want to modify ... I want to be able to move the 'tag' element up or down one node. The problem is the nodes are not unique so it is difficult to find the exact one to work with (and they may be nested several levels). There also may be various parent 'Section' levels that the nodes cannot move around. When it was only one level I was able to do it using the below: IEnumerable XElement > elements = from sections in _scriptXDocument.Elements( "script" ).Elements( "codetags" Read More...
|
-
Hi, How can I convert IEnumerable to EntitySet? var questions = from q in e.Element("Questions").Elements("Question") select new Question { Text = q.Attribute("title").Value, Point = Convert.ToDecimal(q.Attribute("point").Value), Choices = from c in q.Elements("Choices").Elements("Choice") select new Choice { Text = c.Attribute("title").Value, Correct = Convert.ToBoolean(c.Attribute("isCorrect").Value) } }; The lines in bold throw the error: Error 1 Cannot implicitly convert type 'System.Collections.Generic.IEnumerable' Read More...
|
-
I have a simple database with two tables(Task and Status). Task has a column StatusID linked to Status. I am trying to create a windows form with databound fields to do the editing, and I would like the StatusID field to be set using a combobox. Here is some code that has worked for me, but I'm hoping there is a better way. Code Block Public Class FormView Dim db As DataClasses1DataContext = New DataClasses1DataContext Dim taskQuery Dim statusQuery Private Sub FormView_Load( ByVal sender As System.Object, Read More...
|
-
Please take a look of this diagram http://img153.imageshack.us/img153/4351/dbej9.png Anyone show me how could I use linq to do the query below: Select all restaurants that are not in the monthly restaurant list for the last x month.(e,g x= 12) Select all restaurants that are not in weekly restaurant list for the last x week (e.g x= 11) and not the same as the current monthly restaurant. Select all restaurants that are not a current weekly restaurant and not a current monthly restaurant Thank you Read More...
|
-
Hi, I have the following LINQ query. The query searches for bus links between two busstops. var linksQuery = ( from l in DataContext.LinksQuery join lbs1 in DataContext.LinkBusStops on l.ID equals lbs1.LinkID join lbs2 in DataContext.LinkBusStops on l.ID equals lbs2.LinkID where ((lbs1.BusStopID == FromBusStopID) || (FromBusStopID == 0)) && ((lbs2.BusStopID == ToBusStopID) || (ToBusStopID == 0)) && ((l.CompanyID == CompaniesList.SelectedID) || (CompaniesList.SelectedID == 0)) orderby l.SearchDayFee Read More...
|
-
I have created a dbml file with sqlmetal based on an SQL CE 3.5 database, however when I try and run up a simple application the connection fails, saying Provider 'System.Data.SqlServerCe.3.5' not installed. I am running Vista on a 64 bit machine. Read More...
|
-
My goal is to get data from a Stored Procedure to a CSV file. I'm calling the SPROC like this: Code Block System.Data.DLinq. StoredProcedureResult FundGetUnshippedOrdersResult > results = context.FundGetUnshippedOrders(); I found a library that will go from DataTable->CSV. Is there an easy way to go from StoredProcedureResult->DataTable? Thanks. Brian Read More...
|
-
I created a northwind dbml. Only two tables, Product and Category. I wanted to delete the products based on ID. But I can't. The RemoveAll is not defined. Anyone know how to resolve this? NorthwindDataContext db = new NorthwindDataContext(); Product product = db.Products.SingleOrDefault(p => p.ProductID == 1); db.Products.RemoveAll(product) // RemoveAll not defined Thanks. Read More...
|
-
-
Hi, I'm getting the following error when I try to add a new item (Linq to SQL Classes): "Error 1 The custom tool 'MSLinqToSQLGenerator' failed. Object reference not set to an instance of an object." I got this error in Beta 2 (not initially though). I de-installed Beta 2 and installed the RTM Visual Studio 2008, but the same error keeps appearing. Repairing RTM was of no use. I then de-installed RTM and re-installed again, but this didn't help either. When I open an existing dbml file in VS2008, Read More...
|
-
Hi, My environment is .Net 2005 and dlinq preview May 2006 There are n number of problems while fetching data from multiple tables either through join or relations between tables. Consider 2 Entities i) Customers {CustomerID,CustName} ii) Projects {ProjectID, CustomerID,Cost, pName} 1) Using Joins :- var result = from Cust in db.Customers join Proj in db.Projects ON Cust.CustomerID equals Proj.CustomerID select new {Proj.Cost} Problems :- First of All, This query won't compile with some error message Read More...
|
-
Hi all I'm trying to code a dynamic query against a database. The query simply selects the property against which a linq OrderBy command is executed. The code is given below. The problem I have is that I've yet to find out how to reference the type of an "anonymous type" as declared in a var command. In the code below, a reference to this type is needed to replace the placeholder "TSource" in the declaration of 'le' in the method GetAllProducts(). Code Block [ DataObjectMethod ( DataObjectMethodType Read More...
|
-
I am currently reading a book about design patterns in C# (agile principles and patterns in c#) and there its mentioned all the time that it is unwise to create objects directly from the classes (rather use the factory pattern) and to use dependency inversion to keep the design agile. I understand that and think also that its pretty clever :-) Currently I am creating my dbml file from the database and the objects directly from that autogenerated classes. How to realize DIP and the factory architecture? Read More...
|
-
How can i run\compile\call the expression below ("expr") in case that the type defined only in runtime? (the quoted lines are generic and don't applicable in case that the type is dynamic) Code Block Function BuildQuery( ByVal db As DataContext, ByVal type As Type, ByVal field As PropertyInfo, ByVal filter As String ) As IQueryable Dim p As ParameterExpression = Expression.Parameter(type, "p " ) Dim left = Expression.Property(p, type.GetProperty(field.Name)) Dim right = Expression.Constant(filter, Read More...
|
-
I hope I'll get a feedback regarding this issue from MSFT: I still use VS2008 Beta 2. Having a simple entity Foo with ID field (int) as a primary key, the following query is executed successfully: var query = from f in db.Foo select new Foo() { ID = f.ID }; query.ToList(); But when I make a base class BaseEntity : public abstract class BaseEntity { public abstract int ID { get; set; } } and inherit my Foo class from it and set the inheritance modifier of ID to override in Foo , executing the above Read More...
|
-
Trying to replicate the sample of Scott Guthrie on "Using LINQ to SQL" with the Nortwind database on SQL Server 2005, I had no problem this summer with the VS2008 Beta 2 edition. Unfortunately, doing the same steps on the VS2008 RTM version installed today it seems that the Add() method on the tables of the DataContext disappeared... Probably I'm doing something of wrong but on the following code: Code Block NorthwindDataContext db=new NortwindDataContext(); Product product1=new Product(); product1.Name="Toy Read More...
|
-
Hello ! I would like to know if Linq implements the sql "in" ? Example would be : Dim _____MetaCharacteristic_List As List( Of MetaCharacteristic) = _ From M As Characteristic In ____MetaCharacteristic.Characteristic_List _ Where M.ID in (1,2,3) Select M Thanks a lot for any feedback! Regards, Fabianus Read More...
|
-
Can anyone point me to an example of using LINQ with Common Table Expressions in the context of recursive queries ( http://msdn2.microsoft.com/EN-US/library/ms186243.aspx ) Thanks. Read More...
|
-
Hello, I have two tables: [Tags] > TagId, PostId [PostsTags] > TagId, PostId How can I delete, given a TagId, the record from Tags and all records associated with it in PostTags. I have created the Linq to SQL classes. I need to create this code inside my LinqDataSource, which I use as DataSource of my ListView: Private Sub lds_Deleting(ByVal sender As Object, ByVal e As LinqDataSourceDeleteEventArgs) Handles lds.Deleting ... End Sub Could someone, please, help me out? Thanks, Miguel Read More...
|
-
|
|