Click here to Skip to main content
15,868,016 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hi team

I am using entity framework and have an object BIW as bool and on local database i use bit. Problem now its complaining when i try to use on my entity framework method. Let me share the code

What I have tried:

// Model.cs
public class Application_Check {
public bool BIW { get; set; }


//
public ActionResult SaveValuesToDB()
   {
       TimeLineApplicationDBEntities1 bcontext = new TimeLineApplicationDBEntities1();
       var tserver_stations = bcontext.CheckListTables.Select(t => t).ToList();
       if (tserver_stations != null && tserver_stations.Count() > 0)
       {
           foreach (var data in tserver_stations)
           {
               Application_Check model = new Application_Check();
               model.BVMS_PMON = data.BIW;// Cant convert bool to string, how can improve this from doing this?

               //result.Add(model);
           }
       }
       bcontext.SaveChanges();

       return RedirectToAction("ReturnList");
   }
Posted
Updated 22-Nov-21 2:43am
Comments
Richard Deeming 22-Nov-21 8:12am    
Without the exact error message, and the details of the models involved, nobody can help you.
Gcobani Mkontwana 2021 22-Nov-21 8:21am    
@Richard Deeming this is below exact error message
model.BVMS_PMON = data.BVMS; Cannot implicity convert type 'bool' to 'string'
Chris Copeland 22-Nov-21 8:22am    
You've also not provided complete code. If the issue is in model.BVMS_PMON = data.BIW; then you've not given us any code to tell us what this model variable is. Is it a class? We can't see what the BVMS_PMON property is but if I was to guess it's going to be a string, and you cannot assign a bool to a string without converting it.
Gcobani Mkontwana 2021 22-Nov-21 8:25am    
@Chris Copeland yes need to find a way to convert it. Any example will be highly appreciated.
Chris Copeland 22-Nov-21 8:29am    

1 solution

Answered only to remove from unanswered queue: solved by OP / Chris.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900