Linq To SQL-如何从表而不是从数据库获取属性 [英] Linq To SQL - how to have property not from table but from DB

查看:43
本文介绍了Linq To SQL-如何从表而不是从数据库获取属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们将Linq To SQL与我们自己的数据上下文逻辑一起使用,该逻辑在多个数据库中执行一个linq查询.当我们返回结果时,我们需要每个行的数据库.所以...

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...

我想在我的类中拥有一个属性,该属性将返回数据库名称(SQL Server,因此为DB_NAME()).如何在Linq To Sql中做到这一点?

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?

注意:我们有数百个数据库,并且不想在每个数据库中放置视图.返回值应作为返回结果集每一行上的另一个属性返回.

推荐答案

在DBML XML文件中,可以将Column元素的Expression属性设置为此:

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()" />

这篇关于Linq To SQL-如何从表而不是从数据库获取属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆