0

How I can get sql table name in linq

For example : In linq my table object name is : TblUserDetail.

But this table name in sql is TblUserDetails.

Mahmoud Gamal
  • 78,257
  • 17
  • 139
  • 164
Mehdi
  • 105
  • 3
  • 11

3 Answers3

2

Try this:

var model = _db.Mapping; //_db is the datacontext instance
foreach (var mt in model.GetTables())
   Console.WriteLine(mt.TableName);

This will list all sql tables' names.

Quoted from Get all table names

Phil
  • 42,255
  • 9
  • 100
  • 100
Mahmoud Gamal
  • 78,257
  • 17
  • 139
  • 164
1

Ling2sql drops the 's' because the plural is used to identify a collection of TblUserDetails in a related entity.

Probably your TblUSer entity will have a TblUserDetails collection (assumption: you have a 1:n relationship)

Pleun
  • 8,856
  • 2
  • 30
  • 50
0

I've provided an answer for a similar question; however, the answer is for Linq to Entities.

Community
  • 1
  • 1
RePierre
  • 9,358
  • 2
  • 20
  • 37