Using linq to select all tables in database [duplicate] - c#

This question already has answers here:
Linq: Get a list of all tables within DataContext
(4 answers)
Closed 8 years ago.
I want to select list of all tables (Not columns) in a database using LINQ dynamically.
I just want it Dynamically not what listed in DataContext static values.For example i alter Table2 after deploying program. in this situation how i should find it.
By the way of there are any query also please let me know.

I think you can use the "Mapping" feature of LINQ:
context.Mapping.GetTables();

if you want to get tables that are modeled you can use #Mygyll answer, but if you want to list all tables in database you can use SMO, in smo when you have a database you can get all tables via this code
db.Tables.Cast<Table>()

Related

"System.NullReferenceException" Error While Using Linq [duplicate]

This question already has answers here:
EF LINQ include multiple and nested entities
(7 answers)
Closed 1 year ago.
I'm trying to learn one to many relations with EF Core.
In summary: I have two tables; Artists and Songs.
But when I try to reach songs which belongs that artist I am getting error.
Why I'm getting null reference error?
You have to include the related entity you want in the list manually, include Songs like the following way:
var theArtist = DB.Artists.Include("Songs").FirstOrDefault(a => a.ID==1);

Select one row from a table by specifying the row number (Databse) [duplicate]

This question already has answers here:
Row numbers in query result using Microsoft Access
(7 answers)
Closed 4 years ago.
I am currently working on a C# .Net program. This program is connected to an MS Access database.
I am trying to select just one row from a table by specifying the row number, but I can not find any solution for that.
I hope you can help me with my problem :)
You should use primary key or unique column to get 1 row correct data. Other way is very manually and painfull in my opinion. Example
SELECT * FROM Customer WHERE CustomerID=1;
CostumerID is primary key and it bring 1 row to result. If do you realy want to make it manualy i advise add a datagridview in your project and make its visible to false. Fill your all data into it and get what do you want in it. You can access each row easyly.

Is there a get-or-create (lazy loading?) idiom in SQL? [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Solutions for INSERT OR UPDATE on SQL Server
Check if a row exists, otherwise insert
I'm using SQL Server 2008 R2, C# .NET 4.0 (and LINQ).
I want to get or create a row in a table and then append a string to one of its columns.
I'm wondering if there's a best practice for this kind of idiom, or if SQL offers this out of the box?
Somehow transaction start -> select -> insert or update -> transaction end doesn't seem elegant enough...

How to make a select query on a many to many relation using linq? [duplicate]

This question already has an answer here:
Closed 10 years ago.
Possible Duplicate:
Many to many relation linq query in EF
how is it possible to query a many to many relation with linq.
Explanation: i have two tables "conventions" and "participants" with many to many relation the problem is that i can't access the properties of "participants" within the query.
the query:
var conv1 =from c in db.Conventions
where c.objet.Contains(s)
|| c.Domaines.intituleDomaine.Contains(s)
/* snip */
select c;
and i need to join the other table "participants" and search inside it's properties.
Thank you in advance
check this http://www.codeproject.com/Articles/15437/Create-many-to-many-relationships-in-LINQ-for-SQL

Visual Studio Tool to update a DBML? [duplicate]

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
How to update Linq to SQL dbml file?
Is there a quick command in VS2008 to update a DBML that I'm missing or do I have to dleete everything, re-add and then deal with renames and table mods manually? This seems a bit tedious.
DBML so LINQ to SQL; you can delete and re-add a table as one option; that's what we do in our app... curious if there is a better way, but this works quick so that's what we do. THe drop down in the properties window is a quick selector for the table, and we delete, and then bring in the changed table, and it recreates the fields/relationships.
THere isn't an update model from DB like in ADO.NET entity framework.

Categories