简体   繁体   中英

“Sequence contains no matching element” setting HasColumnType(“varchar”) in EF Mappings using Effort

I have the following Entity Framework (v6.1.3) mapping:

public class FileStoreDocumentEntityMapping : EntityTypeConfiguration<FileStoreDocumentEntity>
{
    public FileStoreDocumentEntityMapping()
    {
        Property(x => x.FileStoreDownloadUrl)
            .HasColumnName("FileStoreDetailsUrl")
            .HasColumnType("varchar")
            .HasMaxLength(1000);
        Property(x => x.FileStoreVersion)
            .HasColumnName("FileStoreVersion")
            .HasColumnType("varchar")
            .HasMaxLength(100);
    }
}

Both columns are of data type = "varchar" in my database and sizes are correct: 在此处输入图片说明

However, some of my unit tests are failing with this error:

" System.InvalidOperationException: Sequence contains no matching element "

I read in a related post that you can get the error above if you pass an invalid type to the HasColumnType method but in my case "varchar" should be valid.

Any ideas what could be wrong?

Here is how those properties are defined in my entity:

    public virtual string FileStoreVersion
    {
        get;
        set;
    }

    public virtual string FileStoreDetailsUrl
    {
        get;
        set;
    }

Here is an example of one test that fails in the first line:

    [TestMethod]
    public void Delete_ReturnsSuccess()
    {
        _context.DistributionListSelectionCriteriaDepartmentEntities.Add(_distributionListSelectionCriteriaDepartmentEntity);

_context in this case is of type MemoryEnterprisePaycorCodeFirstContext :

    private void InitializeTestObjects()
    {
        _context = new MemoryEnterprisePaycorCodeFirstContext();

Which inherits from my public class EnterprisePaycorCodeFirstContext : DbContext

That class is where i'm initializing my entity mappings:

    protected override void OnModelCreating(DbModelBuilder modelBuilder)
    {
        modelBuilder.Configurations.Add(new FileStoreDocumentEntityMapping());

Could this be because I'm using Effort MemoryContext vs a Real DB context?

public class MemoryEnterprisePaycorCodeFirstContext : EnterprisePaycorCodeFirstContext
{
    public MemoryEnterprisePaycorCodeFirstContext()
        : base(DbConnectionFactory.CreateTransient())
    {
        Database.CreateIfNotExists();
    }

I figured what it was. Turns out that I was using Effort library which does not support some Column Types as pointed out by @Balah. I used his technique to bypass the entity mapping configuration when coming from my Memory Context: Effort (EF Unit Testing) giving errors

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM