1

We are using Linq To SQL with our own data context logic that executes the one linq query across multiple databases. When we get the results back, we need the database for each of the rows. So...

I want to have a property on my class that will return the database name (SQL Server, so DB_NAME()). How can I do this in Linq To Sql?

NOTE: We have hundreds of databases and do not want to put views in each db. The return should come back as just another property on each row of the return result set.

1
  • can you provide more details on how you're querying against multiple databases? is this done within the application, from the database server via a stored procedure, or how? Commented Oct 23, 2008 at 21:05

2 Answers 2

2

In the DBML XML file, you can set the Expression attribute of a Column element to this:

 <Column Name="Table1.DBName" 
         DbType="nvarahcar(128)" 
         Type="System.String" 
         Expression="DB_NAME()" />
Sign up to request clarification or add additional context in comments.

Comments

0

How are you iterating through the different databases? Could you just include information from the context in the query? For example:

Dim results = _
    From x In myContext.MyTables _
    Select x, info = myContext.Connection.ConnectionString

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.