18

Operator linq as * (asterisk) in sql

 3 years ago
source link: https://www.codesd.com/item/operator-linq-as-asterisk-in-sql.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Operator linq as * (asterisk) in sql

advertisements

I want to select all the fields of one table, and only specifics fields of a second table. Are there any way to do it like with table.* in SQL?

 var things = from t in db.table1
              from t2 in db.table2
              where ...Join Clause...
              select new { t.*,t2.onefield}

obviously this code don't work, but I think it ilustrate my pourpose.

if I use

select new {t,t2.onefield}

it compiles, but it fails when I assign it to a datasource of a datagridview. Currently I'm writing every field that I need of every table.

Thanks.


That isn't good practice in SQL and, even if it can be done with Linq, wouldn't be good practice with Linq either, unless Linq would generate T-SQL code that expands to all the columns of the table.

Related Articles

Is this LINQ statement vulnerable to SQL injection?

Is this LINQ statment vulnerable to SQL injection? var result = from b in context.tests where b.id == inputTextBox.Text select b; where context is an Entity and tests is a table. I'm trying to learn LINQ and I thought that the benefit of it was that

String concatenation operator in Oracle, Postgres, and SQL Server

Is there a way to have a common operator for concatenation in Oracle, Postgres and SQL Server. In Oracle we uses '|', postgres uses '||' and sql server uses '+'. I've solved the problem in postgres by adding the custom operator '+' to support string

What type of operation invoked a trigger in SQL Server 2008?

I'm contemplating a single SQL trigger to handle INSERT, UPDATE and DELETE operations as part of an auditing process. Is there any statement, function or @@ variable I can interrogate to find out which operation type launched the trigger? I've seen t

Why did not the designers of LINQ adopt the way SQL is written today?

For example, why do you do this in LINQ var products = from p in Products select p.Name; when they could have done this: var products = select p.Name from Products p; Does the second offer some limitations in linq? Maybe the above examples are too si

Please help me convert a Linq query to a SQL & hellip; Desperate

Im pretty proficient in LINQ, but not in SQL. I understand cursors are horrible and shouldn't be used. I know SQL Syntax pretty well, but I am trying to figure out how to convert this query and update to SQL from Linq. I don't know how to go through

Operator Linq-To-SQL .ToList ()

Is there a better way of doing this? I have a Linq-To-SQL query that I need to return objects defined by abstract interfaces (e.g. IList<IUser>) rather than concrete objects (e.g. List<User>). // get users from data context List<User> us

How to use c # to perform summation operations with type conversion from SQL using LINQ

I was trying to sum up a column of type nvarchar(7) that I need to first convert data to decimal(18, 7). I used this LINQ query: var Data = queryBase.Select(q => new { totalVol = q.Collection.Sum(c => Convert.ToDecimal(c.Volume) }).FirstOrDefault();

Linq where faster than SQL where

I'm new to SQL, and I'm having some trouble understanding why this Where statement is so inefficient. A bit of background on the database. It's an SQL Compact Edition database which is used to store icons. A project can have multiple icons, each icon

LINQ equivalent of my SQL query for UNION ALL

(SELECT * FROM SheetHay WHERE SheetStatus = 2) UNION ALL(SELECT * FROM SheetHay WHERE SheetStatus = 1) UNION ALL (SELECT * FROM SheetHay WHERE SheetStatus = 0) UNION ALL(SELECT * FROM SheetHay WHERE SheetStatus= 3) I get result set like this: I mean

VS LINQ Entity Framework to SQL VS ADO.NET with Stored Procedures?

How would you rate each of them in terms of: Performance Speed of development Neat, intuitive, maintainable code Flexibility Overall I like my SQL and so have always been a die-hard fan of ADO.NET and stored procedures but I recently had a play with

LINQ, Skip, OrderBy, and SQL Server 2000

I'm accessing a data context object that is auto-generated by using LINQ to SQL. The SQL database is a SQL Server 2000 box. The class I'm working with is a SQL View. I have a statement that is similar to this: query = _context.OrderDetails .Where(w =

Linq Query for Corresponding SQL

Below is my SQL Statement, I am Unable to Convert to LINQ select o.CustId,c.CustName,Count(o.CustId) as Total_Orders from Customer c inner join Orders o on c.CustId = o.CustId group by o.CustId,c.CustName What about something like this? var query = d

What is the easiest way to find the LINQ statement for an SQL statement

I am a SQL Server DBA for a company that sells an ASP.NET MVC3 application that uses LINQ and Entity Framework 4 for all database access. When I find an inefficient query in my SQL Server's plan cache that was generated by LINQ, I would like to be ab

Can I use Linq with View of sql server?

As per my understanding Views could improve performance and I intend to use Views in my database and because my database is huge, I want to create the views for different queries. Is there any way to access the Views in .Net Windows applications or c

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK