Given the ff
SELECT foo1, foo2 result,foo3 FROM tblFOO
And you want to put a condition like
Where result =1
You can do it inside a ‘select’ statement and do it from there as so
SELECT * from
(SELECT foo1, foo2 result foo3 FROM tblFOO ) where result=1
In regards to our recent experience with the .ToList() function, it has come to our attention that we should have been using IEnumerable when gathering data from our Entities instead of returning a type of List in which we have to cast it using ToList() method. Why you ask? It is because using an object with type of IEnumerable gives us time to set aside the system’s data gathering until such that it is needed.
-What Are You Saying?
Think of this as something like Lazy Loading , where you put off data retrieval so that you can optimize the performance of your software where possible. Just remember to cast your IEnumerables to Lists so that you can manipulate your data more efficiently when needed.
Happy Coding >:]
I have an extra 30 mins for the day so I decided to make a quick blog about the first thing that I will remember from my early days of coding . For all you guys that is not that much familiar with LINQ or Language Integrated Query, let’s just say that it’s a feature introduced in Visual Studio 2008.
LINQ is defined by MSDN here
Language-Integrated Query (LINQ) is a set of features introduced in Visual Studio 2008 that extends powerful query capabilities to the language syntax of C# and Visual Basic. LINQ introduces standard, easily-learned patterns for querying and updating data, and the technology can be extended to support potentially any kind of data store.
In plain english, LINQ queries will let you query in Visual Studio without defining any stored procedure or string connections. An example is as follows
A basic SQL select like below
Select name from table1 where table1.id=1
will look like this in LINQ
var name=(from p in datacontext.table1
If we use .First() and the result list is returned empty, LINQ will throw an error. It assumes by saying .First() that it will return a result for it’s like saying SELECT TOP 1 in SQL.
Just a quick post on the go!
DBCC CHECKIDENT(‘Table_Name’, RESEED, 0)
The above line will reset your identity seed to 0, making the next insert’s identity to 1. I’m pretty sure I have tried another way to do it but I cant recall it as of the moment. Hope this helps!