我有一个简单的查询,我想这样做:
1)Products有ChildProducts哪些有PriceTiers
2)我想得到所有Productsa Category的a ID为1和Display= true.
3)我想包含所有ChildProducts有Display= true的东西.
4)然后包括PriceTiershas IsActive= true.
根据我的阅读,EF不支持使用过滤器进行预先加载,因此以下内容不起作用:
ProductRepository.Query.IncludeCollection(Function(x) x.ChildProducts.Where(Function(y) y.Display).Select(Function(z) z.PriceTiers.Where(Function(q) q.IsActive))).Where(Function(x) x.Categories.Any(Function(y) y.ID = ID)))
Run Code Online (Sandbox Code Playgroud)
有什么建议?
我一直致力于使用EF4,POCO域对象和存储库< - >服务层的新MVC应用程序.
我看到很多关于使用AutoMapper将EF4类映射到View模型的DTO的讨论.我的印象是,这是为了摆脱紧密绑定的EF4类.所以我的问题是因为我正在使用POCO类,我不能只使用View Models中的那些吗?或者是否还需要AutoMapper?
我有一个简单的问题.
我有一个看起来像这样的模型:
public class AddEditChildProductModel
{
    public string Name {get; set;}
    public string Sku {get;set;}
    ........
    public IEnumerable<AddEditPriceTierModel> PriceTiers {get;set;}
}
public class AddEditPriceTierModel
{
    public int QtyStart {get;set;}
    public int QtyEnd {get;set;}
    ........
}
Run Code Online (Sandbox Code Playgroud)
我的问题是如何在同一视图中编辑集合?
这似乎很简单,也许我错过了一些东西.
谢谢!!
**编辑**
好的,所以我使用了EditorTemplates,但现在我收到以下错误:
The operation failed: The relationship could not be changed because one or more of the foreign-key properties is non-nullable. When a change is made to a relationship, the related foreign-key property is set to a null value. If the foreign-key …Run Code Online (Sandbox Code Playgroud) 我试图使用MOQ测试存储库来模拟repo的行为.我对MOQ不熟悉,所以请耐心等待.
给出以下方法:
public static SubmissionVersion DeleteNote(IRepository repository, SubmissionVersion version, Guid noteId)
{
    Note note = repository.GetById<Note>(noteId);
    version.Notes.Remove(note);
    repository.Save(version);
    repository.Delete(note);
    return repository.GetById<SubmissionVersion>(version.Id);
}
Run Code Online (Sandbox Code Playgroud)
这个测试看起来不错吗?
[Fact]
public void DeleteNoteV2()
{
    // Arrange
    var note = new Note{ Id = Guid.NewGuid()};
    var subVersion = new Mock<SubmissionVersion>();
    subVersion.Setup(x => x.Notes.Remove(note));
    var repo = new Mock<IRepository>();
    repo.Setup(x => x.GetById<Note>(note.Id)).Returns(note);
    repo.Setup(x => x.GetById<SubmissionVersion>(It.IsAny<Guid?>())).Returns(subVersion.Object);
    // Act
    SubmissionVersion.DeleteNote(repo.Object, subVersion.Object, note.Id.Value);
    // Assert
    repo.Verify(x => x.GetById<Note>(note.Id), Times.Once());
    repo.Verify(x => x.Save(subVersion.Object), Times.Once());
    repo.Verify(x => x.Delete(note), Times.Once());
    subVersion.Verify(x => x.Notes.Remove(It.IsAny<Note>()), Times.Once()); …Run Code Online (Sandbox Code Playgroud) 我正在使用 xUnit 和 Moq 来编写我的单元测试,并且在我的各种测试中我有很多重复的代码,我想将它们提取为某种可重用的方式。
重复代码
var note = new Note { Id = Guid.NewGuid() };
    var subVersion = new Mock<SubmissionVersion>();
    subVersion.Setup(x => x.Notes.Remove(note));
    var repo = new Mock<IRepository>();
    repo.Setup(x => x.GetById<Note>(note.Id)).Returns(note);
    repo.Setup(x => x.GetById<SubmissionVersion>(It.IsAny<Guid?>())).Returns(subVersion.Object);
Run Code Online (Sandbox Code Playgroud)
鉴于以下测试,我如何清理它们以免重复?
[Fact]
public void Should_CallRepoGetNoteByIdOnce()
{
    // Arrange
    var note = new Note { Id = Guid.NewGuid() };
    var subVersion = new Mock<SubmissionVersion>();
    subVersion.Setup(x => x.Notes.Remove(note));
    var repo = new Mock<IRepository>();
    repo.Setup(x => x.GetById<Note>(note.Id)).Returns(note);
    repo.Setup(x => x.GetById<SubmissionVersion>(It.IsAny<Guid?>())).Returns(subVersion.Object);
    // Act
    SubmissionVersion.DeleteNote(repo.Object, subVersion.Object, note.Id.Value);
    // Assert
    repo.Verify(x …Run Code Online (Sandbox Code Playgroud) 我希望能够从a加载指令的模板promise.例如
template: templateRepo.get('myTemplate')
Run Code Online (Sandbox Code Playgroud)
templateRepo.get 返回一个promise,当解析时,它具有字符串中模板的内容.
有任何想法吗?
有人可以解释使用这种模式的好处吗?
我的意思是EF在某种意义上来说不是一个存储库吗?你不能只查询容器并返回那些对象吗?
我看到很多关于POCO,AutoMapper,依赖注入,服务层,IoC的讨论.我只是将一堆东西混合在一起,还是一切都有关系?
谁可以给我解释一下这个?
另外,这些如何与MVC.net,ViewModels和DataModels结合在一起?
谢谢,山姆
dependency-injection poco repository-pattern entity-framework-4
在上下文The directory where your SQL scripts are. Defaults to .\中.\表示您当前所在的目录?
怎么样..\?
关于什么 SET DIR=%~d0%~p0%
angual.module('app')和之间有什么区别module('app')?
以下是有问题的简单服务和单元测试:
服务
(function () {
    "use strict"
    var app = angular.module('app', []);
    app.service('CustomerService', ['$http', function ($http) {
        return {
            getById: function (customerId) {
                return $http.get('/Customer/' + customerId);
            }
        }
    }]);
}());
Run Code Online (Sandbox Code Playgroud)
测试
describe('Customer Service', function () {
    var $rootScope,
        $httpBackend,
        service,
        customerId = 1;
    beforeEach(function () {
        angular.module('app', ['ngMock']);
        inject(function ($injector) {
            $rootScope = $injector.get('$rootScope');
            $httpBackend = $injector.get('$httpBackend');
            $httpBackend.whenGET('/Customer/' + customerId).respond({ id: customerId, firstName: 'Joe', lastName: 'Blow' });
            service = $injector.get('CustomerService');
        });
    });
    afterEach(function () { …Run Code Online (Sandbox Code Playgroud) 我有一点服务将blob上传到Azure存储.我试图从WebApi异步操作中使用它,但我AzureFileStorageService说流已关闭.
我是async/await的新手,是否有任何好的资源可以帮助我更好地理解它?
WebApi控制器
public class ImageController : ApiController
{
    private IFileStorageService fileStorageService;
    public ImageController(IFileStorageService fileStorageService)
    {
        this.fileStorageService = fileStorageService;
    }
    public async Task<IHttpActionResult> Post()
    {
        if (!Request.Content.IsMimeMultipartContent())
        {
            throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.UnsupportedMediaType));
        }
        await Request.Content.ReadAsMultipartAsync(new MultipartMemoryStreamProvider()).ContinueWith((task) =>
        {
            foreach (var item in task.Result.Contents)
            {
                using (var fileStream = item.ReadAsStreamAsync().Result)
                {
                    fileStorageService.Save(@"large/Sam.jpg", fileStream);
                }
                item.Dispose();
            }
        });
        return Ok();
    }
}
Run Code Online (Sandbox Code Playgroud)
AzureFileStorageService
public class AzureFileStorageService : IFileStorageService
{
    public async void Save(string path, Stream source)
    {
        await CloudStorageAccount.Parse(ConfigurationManager.AppSettings["StorageConnectionString"])
            .CreateCloudBlobClient() …Run Code Online (Sandbox Code Playgroud) c# ×3
unit-testing ×3
angularjs ×2
poco ×2
xunit ×2
xunit.net ×2
asp.net-mvc ×1
asynchronous ×1
automapper ×1
azure ×1
batch-file ×1
javascript ×1
moq ×1