Sequence contains no matching element - EntityFramework

后端 未结 10 1647
盖世英雄少女心
盖世英雄少女心 2020-12-17 08:43

I\'m using EF 6.1.0 and was creating a WCF Service.

First I created a Class Library containing my entities, Mappers and Context for initializing EF. I\'ve also creat

相关标签:
10条回答
  • 2020-12-17 09:35

    For me this message was because of misunderstanding for TypeName in Column attribute.

    Column Attribute: [Column (string name, Properties:[Order = int],[TypeName = string])

    name: Name of a column in a db table.
    Order: Order of a column, starting with zero index. (Optional)
    TypeName: Data type of a column. (Optional)

    This TypeName must be only name of the type and must not include precision or scale or length and any other thing. For example following will cause an error

    [Column(TypeName = "nvarchar(600)")]

    while below one will work fine however you might want to have specific size of the column and for that one way is to use fluent API

    [Column(TypeName = "nvarchar")]

    0 讨论(0)
  • 2020-12-17 09:36

    For me it helped, when switched class project to Set as startup project

    0 讨论(0)
  • 2020-12-17 09:44

    I had a bug where I got a System.InvalidOperationException with the message Sequence contains no matching element because I had an incorrect string value being passed to .HasColumnType() in my table configuration.

    0 讨论(0)
  • 2020-12-17 09:46

    Entity Framework throws this exception if the column type is invalid. For example:

    // This will throw an error. There is no such type name.
    [Column(TypeName = "Invalid")]
    public string Column1 { get; set; }
    
    // Works.
    [Column(TypeName = "varchar")]
    public string Column1 { get; set; }
    

    See these examples:

    • Example 1
    • Example 2
    • Other examples in comments.
    0 讨论(0)
提交回复
热议问题