实体框架

发布于 2024-10-21 13:23:51 字数 1105 浏览 0 评论 0原文

我使用以下代码。但是,我尝试使用表名称来检索数据和实体。

        SalesInvoiceList = (from p in entities.SalesCards
                            select new SalesInvoice
                            {
                                ID = p.ID,
                                InvoiceNo = p.InvoiceNo,
                                DateTime = p.DateTime,
                                ContactName = p.CustomerCard.ContactName,
                                CompanyName = p.CustomerCard.CompanyName
                            }).ToList();

我希望能够执行以下操作或类似的操作,

        SalesInvoiceList = (from p in "DBO.SALESCARD"
                            select new SalesInvoice
                            {
                                ID = p.ID,
                                InvoiceNo = p.InvoiceNo,
                                DateTime = p.DateTime,
                                ContactName = p.CustomerCard.ContactName,
                                CompanyName = p.CustomerCard.CompanyName
                            }).ToList();

最好的方法是什么?

谢谢

I Have the following code that I use. However, I'm trying to use the Table Name to retrieve the data and the entities.

        SalesInvoiceList = (from p in entities.SalesCards
                            select new SalesInvoice
                            {
                                ID = p.ID,
                                InvoiceNo = p.InvoiceNo,
                                DateTime = p.DateTime,
                                ContactName = p.CustomerCard.ContactName,
                                CompanyName = p.CustomerCard.CompanyName
                            }).ToList();

I want to be able to do the following or something similar

        SalesInvoiceList = (from p in "DBO.SALESCARD"
                            select new SalesInvoice
                            {
                                ID = p.ID,
                                InvoiceNo = p.InvoiceNo,
                                DateTime = p.DateTime,
                                ContactName = p.CustomerCard.ContactName,
                                CompanyName = p.CustomerCard.CompanyName
                            }).ToList();

What is the best way to do that?

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

故人爱我别走 2024-10-28 13:23:51

您始终可以使用 EF 将某些查询映射到您的对象

Db.Database.SqlQuery<SalesInvoice>("SELECT ID, InvoiceNo, DateTime, ContactName, CompanyName FROM dbo.[SALESCARD]");

You can always use EF just to map some query to your object

Db.Database.SqlQuery<SalesInvoice>("SELECT ID, InvoiceNo, DateTime, ContactName, CompanyName FROM dbo.[SALESCARD]");
如果没有你 2024-10-28 13:23:51

不确定我是否理解您想要正确执行的操作,但如果我理解的话,这应该是您尝试执行的操作的一个简单解决方案。

  public List<SalesInvoice> GetSalesInvoices()
    {
       var _db = new yourDbContext();

    var query = _db.TableThatHasSalesInvoices;

    return query.ToList(); 
    }

Not sure if i am understanding what you want to do correctly but if i am this should be a easy solution to what you are trying to do.

  public List<SalesInvoice> GetSalesInvoices()
    {
       var _db = new yourDbContext();

    var query = _db.TableThatHasSalesInvoices;

    return query.ToList(); 
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文