Quantcast
Channel: ADO.NET, Entity Framework, LINQ to SQL, NHibernate
Viewing all articles
Browse latest Browse all 1698

EF Core - .Include()

$
0
0

Trying to get my head around EF Core.

I have an existing db and used this to generate the EfModel. I can get the list of Transactions to display in a Blazor Server app.

There is a Transactions table and a Client table ( 1 to 1).

Created a new class called ProviderTxnSummary as follows:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace SssEf.EfModel
{
    public class ProviderTxnSummary
    {
        public int TransactionId { get; set; }
        public string Location { get; set; }
        public string OName { get; set; }
        public string State { get; set; }
        public string CName { get; set; }
        public int ClientId { get; set; }
        public int BillNo { get; set; }
        public bool IsBilled { get; set; }
        public string Service { get; set; }
        public string Charge { get; set; }
        public decimal Tax { get; set; }
        public DateTime TDate { get; set; }
        public DateTime BDate { get; set; }
        public bool IsPaid { get; set; }
    }

CName is in Clients

In class Dto:

using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace SssEf.EfModel
{
    public class Dto
    {
        BTContext _db = new BTContext();

        public List<ProviderTxnSummary> GetTransactions()
        {
            return _db.Transactions
                .Include(c => c.Client)
                .OrderByDescending(t => t.Tdate)
                .ToList();
        }
    }
}

Squiggles as indicated by the pink, with a complaint about "Cannot implicitly convert type 'System.Collections.Generic.List<SssEf.EfModel.Transaction>' to 'System.Collections.Generic.List<SssEf.EfModel.ProviderTxnSummary>' "

What am I doing wrong here?


Viewing all articles
Browse latest Browse all 1698

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>