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

EF Linq How to exclude fields?

$
0
0

Hello,

Since I marked my other post as answered, I decided to write a new post. I would like to know if there is a way to exclude fields from linq query.

Here is my sample linq:

var gameBankResult =
                await (context.GameBanks.Where(c => c.productCode == initiate.productCode)).Take(initiate.quantity)
                    .Select(c => new {c.quantity, c.currency, c.initiationResultCode, c.productCode, c.productDescription, c.referenceId, c.responseDateTime, c.unitPrice, c.totalPrice, c.coupons}
                    ).
                    ToListAsync();

And here is models:

public class GameBank
    {
        public int GameBankID { get; set; }
        public string referenceId { get; set; }
        public string productCode { get; set; }
        public int quantity { get; set; }
        public string version { get; set; }
        public DateTime? requestDateTime { get; set; } = DateTime.Now;
        public int? customerID { get; set; }
        public string password { get; set; }
        public DateTime? responseDateTime { get; set; } = DateTime.Now;
        public string initiationResultCode { get; set; }
        public string companyToken { get; set; }
        public int used { get; set; }
        public string productDescription { get; set; }
        public string currency { get; set; }
        public double unitPrice { get; set; }
        public double totalPrice { get; set; }
        public virtual List<GameCouponBank> coupons { get; set; }
    }

public class GameCouponBank
    {
        public int Id { get; set; }
        public int GameBankID { get; set; }
        public DateTime? expiryDate { get; set; }
        public string Serial { get; set; }
        public string Pin { get; set; }

    }

I would like to exclude Id and GameBankID from GameCouponBank.Is there a way to do it?

Best Regards.


Viewing all articles
Browse latest Browse all 1698

Trending Articles



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