TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Naruto Reddy
NA
123
38.8k
The name Savechanges() does not exist in the current context
Jun 16 2020 7:07 AM
Hello Experts,
I am migrating my code from EF to EF Core.
We do have an Igenericreposirory.
And this Igenericreposirory is inheriting by Genericreposirory.
IGenericreposirory
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Threading.Tasks;
namespace DataLayer.Repositories.Base
{
public interface IGenericRepository
where T : class
{
T Add(T entity);
}
}
GenericRepository:
public class GeneralRepository
: IGenericRepository
where T : class, IEntity
, new()
{
protected readonly DbContext DbContext;
internal DbSet
DbSet;
public GeneralRepository(DbContext dbContext)
{
if (dbContext == null)
throw new ArgumentNullException("dbContext");
this.DbContext = dbContext;
this.DbSet = this.DbContext.Set
();
}
public virtual T Add(T entity)
{
#region Argument Validation
if (entity == null)
{
throw new ArgumentNullException("entity");
}
#endregion
var obj = DbSet.Add(entity);
SaveChanges();
return obj;
}
}
Here I am getting 2 errors while working with EF core
1 at return obj as "Cannot convert from 'Microsoft.EntityFrameworkCore.ChangeTracking.EntityEntry
' to 'T'"
2 at Savechange() as "the name savechanges()" does not exists in the current context.
As far as i know , EF core supports all methods to fetch , Insert, ADD
Reply
Answers (
2
)
Facial recognition issue
How to add Active Directory to login form