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

Linq EF query question

$
0
0

Hello everyone,

I have a web api rest service. I am trying to linq query and retrieve data but somehow coupons is null. 

Here is my sample linq:

var codeBankResult = await (context.CodeBanks.Where(c => c.productCode == initiate.productCode))
                .Take(initiate.quantity).FirstOrDefaultAsync();
clarified verison:
var codeBankResult = await (context.CodeBanks.Where(c => c.productCode == 12345)) .Take(1).FirstOrDefaultAsync();

Here is my models I am trying to query:

public class CodeBank
    {
        public int Id { 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 List<CodeBankCoupon> coupons { get; set; }
    }

public class CodeBankCoupon
    {
        public int Id { get; set; }
        public int CodeBankID { get; set; }
        public List<string> serials { get; set; }
        public List<string> pins { get; set; }
        public virtual CodeBank codeBank { get; set; }
        public DateTime? expiryDate { get; set; }
        public List<string> StringsSerial
        {
            get { return serials; }
            set { serials = value; }
        }
        public List<string> StringsPin
        {
            get { return pins; }
            set { pins = value; }
        }

        [Required]
        public string Serial
        {
            get { return String.Join(",", serials); }
            set { serials = value.Split(',').ToList(); }
        }
        [Required]
        public string Pin
        {
            get { return String.Join(",", pins); }
            set { pins = value.Split(',').ToList(); }
        }
    }

And there is indeed 2 rows of data in the CodeBankCoupon. I am trying to implement similar coupon structure as this example:

{"referenceId":"0000000046","paymentId":"MDO1037624","productCode":"001002461285","quantity":"1","currency":"TL","unitPrice":"46,47","totalPrice":"46,47","merchantProductCode":"","purchaseStatusCode":"00","purchaseStatusDate":"2019-03-17T20:58:48Z","coupons":
[
{
"serials":["c57a55b5-b2d4-46e7-86e0-0000000"],"pins":["AADP-4423-ARAX","AAKDA16481"] }, {"serials":["f4d35a31-a388-4b09-84a1-90711111"],"pins":["Q849-VGDJ-XC9HL-XQJB-AAAA"] } ],"version":"V1","signature":"2f961c7dbc32c3bc128b6e69d19e8e1a","applicationCode":"52e7cf966b724749a7c4efadc3727ed7" }


Viewing all articles
Browse latest Browse all 1698

Trending Articles



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