1

I have face problem about entity framework in mcv c#, i decide to change the way to exec query to normally query scripting, this bellow script I have for exemple

//for only one row result
string activeUser = await db.Users.Where(x => x.Token.Equals(token)).Select(x => x.Username).FirstOrDefaultAsync();

ReceivingSFG receiving = await db.ReceivingSFGs.Where(s => s.ID.Equals(receivingVM.ID)).FirstOrDefaultAsync();


//for multiple row result (List)
IQueryable<ReceivingSFGDetail> query = db.ReceivingSFGDetails.Where(s => s.ReceivingID.Equals(req.ID)).AsQueryable();
            IEnumerable<ReceivingSFGDetail> list = Enumerable.Empty<ReceivingSFGDetail>();
            list = query.ToList();
            IEnumerable<ReceivingSFGDetailDTO> listDto = Enumerable.Empty<ReceivingSFGDetailDTO>();
            string message = "";
            bool status = false;
            listDto = from x in list
                   select new ReceivingSFGDetailDTO
                   {
                       ID = x.ID,
                       ReceivingID = x.ReceivingID,
                       Barcode = x.Barcode,
                       QtyActual = x.QtyActual,
                       QtyBag = x.QtyBag,
                       CreatedBy = x.CreatedBy,
                       CreatedDate = x.CreatedDate,
                       QtyPerBag = x.QtyPerBag
                   };

or some case that I never use before, like how to exec store procedure... please some one can help me to solve this case.

1 Answer 1

0

If you want to execute Stored Procedure vie Entity framework you will of course have to start by mapping it into the data context.

Once the stored procedure is mapped in your model layer you can simply call it pseudo like this:

List<SomeStuff_Result> list = _db.NameOfStoredProcedure(string somevariable).ToList();

It should behave the same way any object you receive from data layer.

You can also check this answer.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.