我想知道是否使用带有EF的ASP.NET Boilerplate,是否可能:
我在线搜索,但我找不到答案。
答案 0 :(得分:2)
关于您的问题的示例
public class MyEntity : Entity<string>
{
[NotMapped]
public override string Id
{
get { return MyIntField + "-" + MyStringField ; }
set { /* no need set */ }
}
[Key]
[Column(Order = 1)]
public virtual int MyIntField { get; set; }
[Key]
[Column(Order = 2)]
public virtual string MyStringField { get; set; }
public virtual string OtherField { get; set; }
}
然后像这样使用您的存储库
public class MyEntityAppService: IMyEntityAppService {
private readonly IRepository < MyEntity, string > _myEntityRepository;
public AccountAppService(IRepository < MyEntity, string > myEntityRepository) {
_myEntityRepository = myEntityRepository;
}
public void Test() {
_myEntityRepository.Insert(new MyEntity {
MyIntField = 1,
MyStringField = "test",
OtherField = "Alper Ebicoglu"
});
var myAllEntities = _myEntityRepository.GetAllList();
var myFilteredEntity = _myEntityRepository.Single(s => s.MyIntField == 1 &&
s.MyStringField == "test");
}
// ...
}
PS:某些存储库方法可能无法按预期工作。所以在实施解决方案之前测试所有存储库方法