I just asked this question. Which lead me to a new question :)
Up until this point, I have used the following pattern of selecting stuff with Linq to SQL, with the purpose of being able to handle 0 "rows" returned by the query:
var person = (from p in [DataContextObject].Persons
where p.PersonsID == 1
select...
I'm trying to start using LINQ and specifically LINQ to SQL but I'm having some difficulties
I've tried this with SqlMetal and now using the database table designer in Visual Studio and I keep getting similar errors, like in this code, using the data context I created with the database layout designer in VS2008.
using System;
using Sys...
does it cost cost effective ?
how can i profile the Sql calls to the server?
...
If I query a table with a condition on the key field as in:
var user = from u in dc.Users
where u.UserName == usn
select u;
I know that I will either get zero results or one result. Should I still go ahead and retrieve the results using a for-each or is there another preferred way to handl...
Is there a way to disable LINQ's object tracking features, without also disabling lazy-loaded child associations?
I'm using LINQ2SQL in a set of integration tests. I'm only using LINQ to verify changes in the database, so I want it to act like a simple data access layer rather than a full ORM. To do this,I set set the data context's Obj...
Is there any reason something like this would not work?
This is the logic I have used many times to update a record in a table with LINQ
DataClasses1DataContext db = new DataClasses1DataContext();
User updateUser = db.Users.Single(e => e.user == user);
updateUser.InUse = !updateUser.InUse;
db.Log = new System.IO.StreamWriter(@"c:\t...
I have this XML in a column in my table:
<keywords>
<keyword name="First Name" value="|FIRSTNAME|" display="Jack" />
<keyword name="Last Name" value="|LASTNAME|" display="Jones" />
<keyword name="City" value="|CITY|" display="Anytown" />
<keyword name="State" value="|STATE|" display="MD" />
</keywords>
I'm getting a record out...
In a previous question I asked how to make "Computed properties" in a linq to sql object. The answer supplied there was sufficient for that specific case but now I've hit a similar snag in another case.
I have a database with Items that have to pass through a number of Steps. I want to have a function in my database that retrieves the C...
I'm playing a bit with LINQ to SQL and overall it's a much better option than what Microsoft had before (DataSet), but it seems that object-oriented capabilities are still limited. Since we currently use a custom persistence framework that created a OO model on top of DataSet, I'm looking to port the framework to a new version building a...
I'm using MS SQL Server 2005. Is there a difference, to the SQL engine, between
SELECT * FROM MyTable;
and
SELECT ColA, ColB, ColC FROM MyTable;
When ColA, ColB, and ColC represent every column in the table?
If they are the same, is there a reason why you should use the 2nd one anyway? I have a project that's heavy on LINQ, and I...
Is it possible to use SQL Server 2008 CROSS APPLY with LINQ-2-SQL?
Example SQL:
select d.dateCol, tvf.descr, tvf.value
from dateTable d
cross apply tvFunction(d.dt, 'anotherParam') tvf
where d.category='someCat'
CROSS APPLY enables using values from a table (dateTable in the example) as parameters to a tablevalue function. This is v...
I am working with some tables where I want the C# class to have a different property name than the underlying table column. However, when I use the Translate method to read the results, the properties that don't match the source name never get populated. Even when I use Linq to generate the SQL.
For instance, my table is defined in the ...
I have a string column in a database table which maps to an Enum in code. In my dbml file when I set the "Type" to MyTypes.EnumType I get the following error:
Error 1 DBML1005: Mapping between DbType 'VarChar(50) NOT NULL' and Type 'MyTypes.EnumType' in Column 'EnumCol' of Type 'Table1' is not supported.
This question:
http://stacko...
Let's say I have a table that has a column of XML type data. Within SQL, I can execute the following statement:
select top 10 *,
Content.value('(/root/item/value)[1]', 'float') as Value
from xmltabletest
where Content.value('(/root/item/MessageType)[1]', 'int') = 1
The result set contains only the records matching ...
Just getting started with Linq to SQL so forgive the newbie question. I'm trying to reproduce the following (working) query in Linq to SQL (VB.NET):
Select
f.Title,
TotalArea = Sum(c.Area)
From Firms f
Left Join Concessions c on c.FirmID = f.FirmID
Group By f.Title
Order by Sum(c.Area) DESC
(A Firm has many Concessions; a Conc...
In Scott Hanselman's interview of the stack overflow guys, Scott and Jeff make mention that they may be seen as heretics for declaring that the days of the stored procedure are dead. Why might they say this? Is it because many of the new DAL techniques of dynamic data and Linq to SQL use T-SQL to communicate with the SQL server (SQL 20...
Strange performance outcome, I have a LINQ to SQL query which uses several let statements to get various info it looks like this
public IQueryable<SystemNews> GetSystemNews()
{
using (var t = new TransactionScope(TransactionScopeOption.Required,
new TransactionOptions { IsolationLevel = System.Transactions.Isolatio...
In LinqToSql, it is lovely easy to load a row, change a column, and submit the changes to the database:
using (MyDataContext wdc = new MyDataContext())
{
Article article = wdc.Article.First(p => p.ID == id);
article.ItemsInStock = itemsinstock;
wdc.SubmitChanges();
}
The only drawback: Article is huge. To load the entire...
I am trying to put some distributed caching into play, I'm using this indeXus.Net Shared Cache .
It Requires that the object being cached is serializable, which it is here is the class object.
[Serializable]
public class Members
{
public Members()
{}
public Members(string aspnetusername, string aspnetpassword,
str...
I wanted to compare the datetime which is in this format "7/20/2008" with the ones in the database which is in format "7/20/2008 7:14:53 AM".
I tried using "like" clause but it did not work beacuse the "like" clause uses only string and the one which I am using is date time format.
Can anyone tell how to convert and compare it in datab...