如何在不生成所有类的情况下使用Linq-to-SQL? [英] How to use Linq-to-SQL without having to generate all the classes?

查看:95
本文介绍了如何在不生成所有类的情况下使用Linq-to-SQL?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我以前从未在应用程序中使用过Linq-to-Sql,但我使用过LinqPad来开发查询,只是想将其粘贴到我的代码中.

I have never used Linq-to-Sql before in an application but I used LinqPad to develop a query and just wanted to paste it into into my code.

这不是那么简单.我猜想我需要一个DataContext来处理连接,但是由于无法识别视图名称,我仍然会收到错误消息.

It's not so simple. I guessed that I need a DataContext to handle the connection but I still get errors because the view names aren't recognised.

必须使用设计器并全部创建视图/表类吗?有没有更简单的方法?

Do I have to use the designer and create all the View/Table- classes? Is there a more simple way?

这是查询.不需要任何更新-仅此一项查询....

This is the query. Don't need any updates - just this one query....

var q = from user in V020
    join userapp in V010 on user.SPP_USER_ID equals userapp.SPP_USER_ID
    join app in V030 on userapp.SPP_AW_ID equals app.SPP_AW_ID
    join tx in V040 on app.SPP_AW_ID equals tx.SPP_AW_ID
    join appber in V070 on app.SPP_AW_ID equals appber.SPP_AW_ID
    join ber in V050 on appber.SPP_AW_BEREICH_ID equals ber.SPP_AW_BEREICH_ID 

    where app.SPP_AW_AKTIV && user.SPP_USER_ID == "userid" && tx.SPP_AW_SPR == "de" && ber.SPP_AW_SPR == "de"

    orderby ber.SPP_BER_SORTNB

    select new {
        AppName = app.SPP_AW_KURZBEZ, Url = tx.SPP_AW_URL, Label = tx.SPP_AW_NAME, Description = tx.SPP_AW_BESCHR,
        Bereich = ber.SPP_AW_BERNAME,
        Owner = app.SPP_AW_VERANTW, Remote = app.SPP_AW_REMOTE
    }

    ;

推荐答案

  1. 如上所述创建dbml文件
  2. 打开服务器资源管理器"
  3. 连接到数据库
  4. 将要使用的表从数据库连接拖放到设计器中
  5. 聚会时间

这篇关于如何在不生成所有类的情况下使用Linq-to-SQL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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