0
ddnils created
I have created a custom repository (i had to, my entity has a combined primary key (long,long)).
public class UserRelation
{
public virtual long UserId { get; set; }
public virtual long FriendId { get; set; }
[ForeignKey("UserId")]
public virtual Users.User User { get; set; }
[ForeignKey("FriendId")]
public virtual Users.User Friend { get; set; }
public DateTimeOffset RequestDate { get; set; }
public DateTimeOffset? AcknowledgeDate { get; set; }
public FriendRequestStatus FriendStatus { get; set; }
}
OnModelCreating contains this code to instruct EntityFramework:
modelBuilder.Entity().HasKey(f => new { f.UserId, f.FriendId });
modelBuilder.Entity()
.HasRequired(f => f.User)
.WithMany()
.HasForeignKey(f => f.UserId);
modelBuilder.Entity()
.HasRequired(f => f.Friend)
.WithMany()
.HasForeignKey(f => f.FriendId)
.WillCascadeOnDelete(false);
So I created my custom repository in [].EntityFramework.Repositories Structure:
public class FriendsRepository: EntityFramework.Repositories.IFriendsRepository {}
interface IFriendsRepository : IRepository
{
System.Threading.Tasks.Task ApproveFriendshipAsync(long UserId, long FriendId);
System.Threading.Tasks.Task CreateFriendshipAsync(long UserId, long FriendId);
System.Linq.IQueryable GetAllFriendsOfUserId(long UserId);
System.Linq.IQueryable GetAllRelationsOfUserId(long UserId);
System.Threading.Tasks.Task SetFriendshipStatusAsync(long UserId, long FriendId, Entities.FriendRequestStatus status);
}
But now I wonder how I can inject it into my service structure, since the entityframework project is not referenced in [].Application?
Have I done something wrong? Or is something still missing? Any help is welcome :)
1 Answer(s)
-
0
Hi,
You should create your repository interface in .Core project, implement it in .EntityFramework project. Thus, you can use it from everywhere, including .Application project.