bm_masri
bm_masri

Reputation: 1

entities framework

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

Upvotes: 0

Views: 139

Answers (2)

jackncoke
jackncoke

Reputation: 2020

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(); 
    }

Upvotes: 0

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]");

Upvotes: 1

Related Questions