Showing posts with label Entity Framework. Show all posts
Showing posts with label Entity Framework. Show all posts

Sunday, October 29, 2017

Unable to update the EntitySet - because it has a DefiningQuery and no element exist

When you come across the above error while inserting into the database table using LINQ the reason for that is your Database table doesn't have a primary key I was trying to insert the data into the table which does not have any primary key created on it the solution is to create the primary key on that table.

Sunday, October 16, 2016

The type of one of the expressions in the join clause is incorrect. Type inference failed in the call to 'Join'.

public List<data>GetData()
        {

            return (
                from ud in dbcontext.userdetails
                join td in dbcontext.taskdetails
                on new
                {
                   ud.uid ,
                }
                equals new
                {
                   td.uid.Value ,
                }
                select new data
                {
                    name = td.name,
                    amount = td.amount
                }

                ).ToList();

        }


Solution :- 

public List<data>GetData()
        {

            return (
                from ud in dbcontext.userdetails
                join td in dbcontext.taskdetails
                on new
                {
                   uid =  ud.uid ,
                }
                equals new
                {
                  uid = td.uid.Value ,
                }
                select new data
                {
                    name = td.name,
                    amount = td.amount
                }

                ).ToList();
        }

Tuesday, September 27, 2016

To check the If Exist condition (SqlServer) in linq using c#



public void IfExist(string username)
        {
            var name = dbcontext.userdetails.Any(s => s.username == username);

            if (name == true)
            {
                Console.WriteLine("Record Exists");
            }
            else
            {
                Console.WriteLine("Record Does Not Exists");
            }
        }

To check if any record exist in the table using linq c#



public void CheckRecordExistOrNot()
        {
            var query = (from td in dbcontext.taskdetails select td).ToList();

            if (query.Count > 0)
            {
                Console.WriteLine("Record Exists");
            }
            else
            {
                Console.WriteLine("Record Does Not Exists");
            }
        }

The type parameter 'Entity_Code.display_Result' in ExecuteFunction is incompatible with the type 'bmModel.display_Result' returned by the function



If you get the following error while displaying the data using procedure then follow the below steps :-


Then go to the procedure and select the procedure and select goto definition


Then check the class names if the class names are same and the column names of the results from the table are same 



Now check if the column names from the table are same

 

Now if the result from the table and the class names are not same then change the class names both must be same

Git Commands

Git Version   To check the git version Git -v       Git Clone To clone the repository, use the following command: Git clone [u...