Linq no-noes - catch all sql-like?

One of the things you beat as a junior developer is that you never do "SELECT *" in a dataset, as it is unreliable for several reasons.

Since we are moving to Linq (first, Linq to SQL, and then to the Entity Framework), I wonder if the equivalent of Linq is equivalent?

Eg

var MyResult = from t in DataContext.MyEntity
               where t.Country == 7
               select t;

Should we choose an anonymous type only with the fields that we want to explicitly mention, or now all will choose everything that is available for LinqToSql and others, because of the additional material surrounding the data that they provide?

Hello

Mu

+5
source share
7 answers

, . , t, , , , :

var MyResult = from t in DataContext.MyEntity
               where t.Country == 7
               select new { t.Prop1, t.Prop2 };

. , , , ... , .

, , . , .

+5

select t s . , SQL.

, SQL

INSERT INTO aTable
SELECT * FROM AnotehrTable

, AnotherTable , Linq/.Net .

, select * Linq, , .

+1

, SELECT *, , , , .

SELECT * , , "t" , . , , .

+1

, , , SELECT *. , .

var myResult = from t in DataContext.MyEntity
               where t.Country == 7
               select new T
               {
                   Field1 = t.Field1,
                   Field2 = t.Field2
               }
0

, . , - , , . , , .

0

LINQ .

SELECT * FROM ... LINQ to SQL. SELECT, , ; .

- , , .

0

Perhaps this needs to be done as in the example, especially if you need to make a change to the line (s).

in SQL, select * is different from linq because linq will always return the same number of columns (as defined in dbml).

0
source

All Articles