Class can't be used as parameter for MigrateDatabaseToLatestVersion - c#

I'm rewriting a current working POS system that was created in C# using the .NET Framework. When trying to build the project the compiler returns error CS0311 saying that the type of the parameter given can't be used.
I've researched the used classes and everything it needs according to the .NET documentation is defined in the class so I have no clue why it doesn't work.
The code used in EfDbContext.cs:
using NLog;
using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Data.Entity.ModelConfiguration.Conventions;
using System.Data.Entity.Validation;
using System.Linq.Expressions;
using Dal.Migrations;
using Dal.Model;
namespace Dal
{
public class EfDbContext : DbContext
{
private static readonly Logger logger = LogManager.GetCurrentClassLogger();
public EfDbContext()
: base(Settings.ConnectionString ?? "")
{
Database.SetInitializer<EfDbContext>((IDatabaseInitializer<EfDbContext>) new MigrateDatabaseToLatestVersion<EfDbContext, Configuration>());
EfDbContext.logger.Debug("Database entity context initialized");
}
public DbSet<Member> Members { get; set; }
public DbSet<Role> Roles { get; set; }
public DbSet<Category> Categories { get; set; }
public DbSet<Product> Products { get; set; }
public DbSet<TaxCategory> TaxCategories { get; set; }
public DbSet<Ticket> Tickets { get; set; }
public DbSet<TicketLine> TicketLines { get; set; }
public DbSet<MemberCard> MemberCards { get; set; }
public DbSet<CheckoutSheet> CheckoutSheets { get; set; }
public DbSet<Transaction> Transactions { get; set; }
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Conventions.Remove<OneToManyCascadeDeleteConvention>();
modelBuilder.Entity<Ticket>().HasMany<TicketLine>((Expression<Func<Ticket, ICollection<TicketLine>>>)(p => p.TicketLines)).WithRequired().WillCascadeOnDelete(true);
modelBuilder.Entity<Ticket>().HasMany<Transaction>((Expression<Func<Ticket, ICollection<Transaction>>>)(p => p.Transactions)).WithOptional((Expression<Func<Transaction, Ticket>>)(m => m.Ticket)).WillCascadeOnDelete(true);
modelBuilder.Entity<Member>().HasMany<MemberCard>((Expression<Func<Member, ICollection<MemberCard>>>)(p => p.MemberCards)).WithRequired((Expression<Func<MemberCard, Member>>)(m => m.Member));
modelBuilder.Entity<CheckoutSheet>().HasMany<Ticket>((Expression<Func<CheckoutSheet, ICollection<Ticket>>>)(p => p.Tickets)).WithOptional((Expression<Func<Ticket, CheckoutSheet>>)(m => m.CheckoutSheet)).WillCascadeOnDelete(true);
}
public override int SaveChanges()
{
try
{
return base.SaveChanges();
}
catch (DbEntityValidationException ex)
{
throw new FormattedDbEntityValidationException(ex);
}
}
~EfDbContext()
{
EfDbContext.logger.Debug("Database entity context destroyed");
}
}
}
Code used in Configuration.cs:
using NLog;
using System.Data.Entity;
using System.Data.Entity.Migrations;
namespace Dal.Migrations
{
internal sealed class Configuration : DbMigrationsConfiguration<DbContext>
{
private static readonly Logger logger = LogManager.GetCurrentClassLogger();
public Configuration()
{
this.AutomaticMigrationsEnabled = true;
this.AutomaticMigrationDataLossAllowed = true;
this.ContextKey = "POS.Dal.EfDbContext";
}
protected override void Seed(DbContext context)
{
Configuration.logger.Info("Database migration completed");
}
}
}
[CS0311 error returned by compiler][1]
Error CS0311
The type 'Dal.Migrations.Configuration' cannot be used as type parameter 'TMigrationsConfiguration' in the generic type or method 'MigrateDatabaseToLatestVersion<TContext, TMigrationsConfiguration>'. There is no implicit reference conversion from 'Dal.Migrations.Configuration' to 'System.Data.Entity.Migrations.DbMigrationsConfiguration<Dal.EfDbContext>'.
Dal 2
D:\lagae\Documents\Point Of Sale\POS\Dal
D:\lagae\Documents\Point Of Sale\POS\Dal\EfDbContext.cs
Line 20
Column 134
Does somebody see what I did wrong?
Kind Regards,
Jerlag_01

Related

Unable to create database

When running my program I get this exception: 'Microsoft.Data.Sqlite.SqliteException: 'SQLite Error 1: 'no such table: Tasks'.'
I followed the steps on the Microsoft docs to install EFcore, create the model and create the database. This did the trick on one of my other Maui projects but not on this one since I can't get it to to create the table 'Tasks'.
using Microsoft.EntityFrameworkCore;
using Task = Todo.Models.Task;
namespace Todo.Data
{
class TaskContext : DbContext
{
public DbSet<Task> Tasks { get; set; }
public string DbPath { get; }
public TaskContext()
{
var folder = Environment.SpecialFolder.LocalApplicationData;
var path = Environment.GetFolderPath(folder);
DbPath = System.IO.Path.Join(path, "ToDo.db");
}
// The following configures EF to create a Sqlite database file in the
// special "local" folder for your platform.
protected override void OnConfiguring(DbContextOptionsBuilder options)
=> options.UseSqlite($"Data Source={DbPath}");
}
}
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace Todo.Models
{
public class Task
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int Id { get; set; }
public string Title { get; set; }
public bool IsCompleted { get; set; }
}
}
Edit: Adding Database.EnsureCreated() in the TaskContext constructor fixed it

EF Core: entity requires a key - but it does have a key

I'm using EF Core and have the following project structure
AppName.Entity
Alert
Other classes
AppName.Repository
AlertRepository
Other Repository classes
The alert entity is as follows:
using System;
using System.ComponentModel.DataAnnotations;
namespace AppName.Entity
{
public class Alert
{
[Key]
public int AlertId { get; set; }
public string RuleId { get; set; }
public string DeviceId { get; set; }
public string VehicleVin { get; set; }
public string AlertText { get; set; }
public DateTime DateTimeUtc { get; set; }
public AlertCategory AlertCategory { get; set; }
}
public enum AlertCategory
{
VehicleHealth = 1,
FleetHealth = 2,
EmissionsHealth = 3,
Fuel = 4,
AssetUtilization = 5,
Safety = 6,
DutyCycle = 7
}
}
AlertRepository.cs is as follows:
using AppName.Entity;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace AppName.Repository
{
public class AlertRepository// : GenericRepository<Alert>, IAlertRepository
{
public async Task<int> Save(Alert alert)
{
using (AFIdbContext context = new AFIdbContext())
{
context.Alerts.Add(alert);
await context.SaveChangesAsync();
return alert.AlertId;
}
}
public async Task<bool> Save(IEnumerable<Alert> alerts)
{
using (AFIdbContext context = new AFIdbContext())
{
foreach (Alert alert in alerts)
{
context.Alerts.Add(alert);
}
await context.SaveChangesAsync();
return true;
}
}
public IQueryable<Alert> GetList(DateTime fromDate, DateTime toDate, int pageSize, int pageNum)
{
using (AFIdbContext context = new AFIdbContext())
return context.Alerts.Where(x => x.DateTimeUtc >= fromDate && x.DateTimeUtc <= toDate).Skip(pageSize * pageNum).Take(pageSize);
}
}
}
AFIdbContext.cs
using AppName.Entity;
using Microsoft.EntityFrameworkCore;
using System.Configuration;
namespace AppName.Repository
{
public class AFIdbContext : DbContext
{
private string _afiConnstring;
public string AFIConnstring
{
get
{
if (_afiConnstring != null)
return _afiConnstring;
else
return "";
}
}
public AFIdbContext() : base()
{
}
public AFIdbContext(DbContextOptions<AFIdbContext> options) : base(options)
{
}
public DbSet<Alert> Alerts { get; set; }
public DbSet<User> Users { get; set; }
public DbSet<UserAlertPreference> UserAlertPreferences { get; set; }
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<AlertRepository>().ToTable("Alert");
modelBuilder.Entity<User>().ToTable("User");
modelBuilder.Entity<UserAlertPreference>().ToTable("UserAlertPreference");
}
protected override void OnConfiguring(DbContextOptionsBuilder options)
{
options.UseSqlServer(AppExtensions.ConnString);
}
}
}
When I attempt to save a collection of Alerts, I get the following exception:
System.InvalidOperationException: 'The entity type 'AlertRepository' requires a primary key to be defined. If you intended to use a keyless entity type call 'HasNoKey()'.'
The Alert entity does have a primary key in the DB and does have the [Key] attribute. Why is it telling me that the AlertRepository object doesn't have the key set when it's an Alert Entity I am trying to save? Can I not have the Entity in a separate project? I'm trying to follow a DDD pattern
The exception is being thrown before it even tries to save the records
(I have a breakpoint on await context.SaveChangesAsync(); in AlertRepository
The solution here doesn't help because I already have those set
AlertRepository is not right class to be an entity, you just have to map the Alert entity in OnModelCreating
Replace
modelBuilder.Entity<AlertRepository>().ToTable("Alert");
with
modelBuilder.Entity<Alert>().ToTable("Alert")
or you can just remove this line because entity framework will create a table for you with same name as your entity.
You have mapped the wrong entity in your OnModelCreating for table Alert.
Try with
modelBuilder.Entity<Alert>().ToTable("Alert")

EF Core - One to many with parent and child Inheritance

Summary
I am trying to use Table Per Hierarchy inheritance in conjunction with a one to many relationship in a .Net Core 1.1 project. Both the Parent and child entities use inheritance.
I have a very simple entity model. I have a one base parent entity: Session which has two entities which extend from it: QuotingSession and BackOfficeSession. Both of these two parent entities contain a collection of child entities (a one to many relationship). The child entities are also built using inheritance. There is a base child entity: Policy. This base child entity is extended by two entities: QuotingPolicy and BackOfficePolicy. When I construct either of the Parent entities and attempt to save I receive this exception:
InvalidCastException: Unable to cast object of type 'EFTest.QuotingSession' to type 'EFTest.BackOfficeSession
However, when I tell entity framework to ignore one of the the child collections on either of the parents, the save works for both parent entities with no exception. For example:
var entity = modelBuilder.Entity<BackOfficeSession>();
entity.Ignore(c => c.Policies);
In addition if I do not configure one of the Parents (QuotingSession) at all, and just save the other Parent (BackOfficeSession), everything saves as excepted.
Repo
https://github.com/seantarogers/EFTest
Details
I am using Microsoft.EntityFrameworkCore 1.1.1 and Microsoft.EntityFrameworkCore.SqlServer 1.1.1 in a .Net core 1.1 project.
I have the following simple database schema:
My classes look like this:
1. Session
namespace EFTest
{
public abstract class Session
{
public int Id { get; private set; }
}
}
2. QuotingSession
using System.Collections.Generic;
namespace EFTest
{
public class QuotingSession : Session
{
public string QuotingName { get; private set; }
public List<QuotingPolicy> Policies { get; private set; }
private QuotingSession()
{
}
public QuotingSession(string name, List<QuotingPolicy> quotingPolicies)
{
QuotingName = name;
Policies = quotingPolicies;
}
}
}
3. BackOfficeSession
using System.Collections.Generic;
namespace EFTest
{
public class BackOfficeSession : Session
{
public List<BackOfficePolicy> Policies { get; private set; }
public string BackOfficeName { get; private set; }
private BackOfficeSession()
{
}
public BackOfficeSession(string name, List<BackOfficePolicy> policies)
{
BackOfficeName = name;
Policies = policies;
}
}
}
4. Policy
namespace EFTest
{
public abstract class Policy
{
public int Id { get; set; }
public int SessionId { get; set; }
}
}
5. QuotingPolicy
namespace EFTest
{
public class QuotingPolicy : Policy
{
public string QuotingPolicyName { get; private set; }
private QuotingPolicy()
{
}
public QuotingPolicy(string name)
{
QuotingPolicyName = name;
}
}
}
6. BackOfficePolicy
namespace EFTest
{
public class BackOfficePolicy : Policy
{
public string BackOfficePolicyName { get; private set; }
private BackOfficePolicy()
{
}
public BackOfficePolicy(string name)
{
BackOfficePolicyName = name;
}
}
}
7. EF DB Context and Fluent Configuration
using Microsoft.EntityFrameworkCore;
namespace EFTest
{
public class TestDbContext : DbContext
{
public TestDbContext(DbContextOptions options)
: base(options)
{
}
public DbSet<QuotingSession> QuotingSessions { get; set; }
public DbSet<BackOfficeSession> BackOfficeSessions { get; set; }
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
ConfigureSession(modelBuilder);
ConfigurePolicy(modelBuilder);
ConfigureQuotingSession(modelBuilder);
ConfigureBackOfficeSession(modelBuilder);
ConfigureBackOfficePolicy(modelBuilder);
ConfigureQuotingPolicy(modelBuilder);
}
public static void ConfigurePolicy(ModelBuilder modelBuilder)
{
var entity = modelBuilder.Entity<Policy>();
entity.ToTable("Policy", "dbo");
entity.HasKey(x => x.Id);
entity.HasDiscriminator<int>("SessionType")
.HasValue<QuotingPolicy>(1)
.HasValue<BackOfficePolicy>(2);
}
public static void ConfigureBackOfficePolicy(ModelBuilder modelBuilder)
{
var entity = modelBuilder.Entity<BackOfficePolicy>();
entity.Property(x => x.BackOfficePolicyName);
}
public static void ConfigureQuotingPolicy(ModelBuilder modelBuilder)
{
var entity = modelBuilder.Entity<QuotingPolicy>();
entity.Property(x => x.QuotingPolicyName);
}
public static void ConfigureSession(ModelBuilder modelBuilder)
{
var entity = modelBuilder.Entity<Session>();
entity.ToTable("Session", "dbo");
entity.HasKey(x => x.Id);
entity.HasDiscriminator<int>("SessionType")
.HasValue<QuotingSession>(1)
.HasValue<BackOfficeSession>(2);
}
public static void ConfigureBackOfficeSession(ModelBuilder modelBuilder)
{
var entity = modelBuilder.Entity<BackOfficeSession>();
entity.Property(x => x.BackOfficeName);
entity.HasMany(c => c.Policies).WithOne().HasForeignKey(c => c.SessionId);
// entity.Ignore(c => c.Policies); uncomment this to see it working
}
public static void ConfigureQuotingSession(ModelBuilder modelBuilder)
{
var entity = modelBuilder.Entity<QuotingSession>();
entity.Property(x => x.QuotingName);
entity.HasMany(c => c.Policies).WithOne().HasForeignKey(c => c.SessionId);
}
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
}
}
}
8. To test it
using System;
using System.Collections.Generic;
using Microsoft.EntityFrameworkCore;
namespace EFTest
{
class Program
{
static void Main(string[] args)
{
var optionsBuilder = new DbContextOptionsBuilder<TestDbContext>();
const string conn = "Server=.\\SqlServer2014;Database=EFTest;Trusted_Connection=True"
optionsBuilder.UseSqlServer(conn);
using (var dbContext = new TestDbContext(optionsBuilder.Options))
{
var quotingPolicy = new QuotingPolicy("quotingPolicyname");
var quotingSession = new QuotingSession("quotingSessionName", new List<QuotingPolicy> {quotingPolicy});
dbContext.QuotingSessions.Add(quotingSession);
dbContext.SaveChanges(); // BLOWS UP HERE!
}
}
}
}
Thanks for your help

Entity Framework Core error not seen before Class.TempProperty is of type 'object' which is not supported by current database provider

I am using Entity Framework Core code-first with fluent API entity configurations, in an ASP .NET MVC Core application. My code currently compiles, but when I run add-migration in the Package Manager Console, it gives the error below:
The property 'Exam.TempId' is of type 'object' which is not supported
by current database provider. Either change the property CLR type or
manually configure the database type for it.
Searching Google for this error yields no results. Can anybody here help please?
"Exam" is a class in my domain model, but it doesn't have a "TempId" property so I guess that's something that Entity Framework is adding. It does have an "Id" property, but the type is int, not object.
I'll start by sharing the Exam class and the Exam configuration class. I can share more code if required. I'd be really grateful for any advice you can provide to resolve the problem.
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
namespace MySite.Core.Models
{
public class Exam : ActivatableEntity
{
private int _numberOfQuestionsToBeAttempted;
private Exam()
{
Topics = new Collection<Topic>();
}
public Exam(IUser createdByUser,
string name,
string description,
double timeAllowedInMinutes,
bool shuffleTopicsTogether = true) :
base(createdByUser)
{
Name = name;
Description = description;
Topics = new Collection<Topic>();
TimeAllowedInMinutes = timeAllowedInMinutes;
ShuffleTopicsTogether = shuffleTopicsTogether;
}
public string Name { get; private set; }
public string Description { get; private set; }
public double TimeAllowedInMinutes { get; private set; }
public bool ShuffleTopicsTogether { get; private set; }
public IEnumerable<Question> PossibleQuestions
{
get
{
return Topics.SelectMany(t => t.PossibleQuestions);
}
}
public int NumberOfQuestionsToBeAttempted
{
get
{
if (_numberOfQuestionsToBeAttempted != 0) return _numberOfQuestionsToBeAttempted;
foreach (Topic topic in Topics)
{
_numberOfQuestionsToBeAttempted += topic.NumberOfQuestionsToBeAttempted;
}
return _numberOfQuestionsToBeAttempted;
}
}
public IEnumerable<Topic> Topics { get; }
public void Update(IUser updatedByUser, string name, string description, double timeAllowedInMinutes, bool shuffleTopicsTogether = true)
{
Name = name ?? throw new ArgumentNullException(nameof(name));
Description = description;
TimeAllowedInMinutes = timeAllowedInMinutes;
ShuffleTopicsTogether = shuffleTopicsTogether;
Update(updatedByUser);
}
}
}
Exam configuration class
using MySite.Core.Models;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
namespace MySite.Persistence.EntityConfiguration
{
public class ExamConfiguration
{
public ExamConfiguration(EntityTypeBuilder<Exam> entityBuilder)
{
entityBuilder.HasKey(e => e.Id);
entityBuilder.HasOne(e => (ApplicationUser)e.CreatedByUser)
.WithMany()
.HasForeignKey(e => e.CreatedByUserId)
.OnDelete(DeleteBehavior.SetNull);
entityBuilder.HasOne(e => (ApplicationUser)e.LastUpdatedByUser)
.WithMany()
.HasForeignKey(e => e.LastUpdatedByUserId)
.OnDelete(DeleteBehavior.SetNull);
entityBuilder.Property(e => e.Name).IsRequired().HasMaxLength(50);
entityBuilder.Property(e => e.Description).IsRequired().HasMaxLength(250);
entityBuilder.HasMany(e => e.Topics)
.WithOne(t => t.Exam).OnDelete(DeleteBehavior.Cascade);
}
}
}
As requested by posters, I'm adding the code for the base classes below:
using System;
namespace MySite.Core.Models
{
public abstract class ActivatableEntity :
UpdatableCreatableEntity,
IActivatable
{
protected ActivatableEntity() { }
protected ActivatableEntity(IUser createdByUser) : base(createdByUser) { }
public int? LastActivatedByUserId { get; private set; }
public IUser LastActivatedByUser { get; private set; }
public DateTime? WhenLastActivated { get; private set; }
public int? LastDeactivatedByUserId { get; private set; }
public IUser LastDeactivatedByUser { get; private set; }
public DateTime? WhenLastDeactivated { get; private set; }
public bool IsActive { get; private set; }
protected virtual void Activate(IUser activatedByUser)
{
LastActivatedByUser = activatedByUser ?? throw new ArgumentNullException(nameof(activatedByUser));
LastActivatedByUserId = activatedByUser.Id;
WhenLastActivated = DateTime.Now;
IsActive = true;
}
protected virtual void Deactivate(IUser deactivatedByUser)
{
LastDeactivatedByUser = deactivatedByUser ?? throw new ArgumentNullException(nameof(deactivatedByUser));
LastDeactivatedByUserId = deactivatedByUser.Id;
WhenLastDeactivated = DateTime.Now;
IsActive = false;
}
}
public abstract class UpdatableCreatableEntity :
CreatableEntity,
IUpdatable
{
protected UpdatableCreatableEntity() { }
protected UpdatableCreatableEntity(IUser createdByUser) : base(createdByUser) { }
public int? LastUpdatedByUserId { get; private set; }
public IUser LastUpdatedByUser { get; private set; }
public DateTime? WhenLastUpdated { get; private set; }
protected virtual void Update(IUser updatedByUser)
{
LastUpdatedByUser = updatedByUser ?? throw new ArgumentNullException(nameof(updatedByUser));
LastUpdatedByUserId = updatedByUser.Id;
WhenLastUpdated = DateTime.Now;
}
}
public abstract class CreatableEntity :
IIdentifiable,
ICreatable
{
protected CreatableEntity() { }
protected CreatableEntity(IUser createdByUser)
{
CreatedByUser = createdByUser ?? throw new ArgumentNullException(nameof(createdByUser));
CreatedByUserId = createdByUser.Id;
WhenCreated = DateTime.Now;
}
public int Id { get; private set; }
public int? CreatedByUserId { get; private set; }
public DateTime WhenCreated { get; private set; }
public IUser CreatedByUser { get; private set; }
}
}
I faced same problem and it confused me a lot. But luckily I was using version control, so I was able to trace reasons of the issue.
For me it was many-to-many relation entity model with constructor that assigns values to fields. I was relying to Visual Studio to generate properties for me automatically, and VS did poor job not detecting type of the property that later became a key.
VS created property of type object, which is too generic and hardly could be translated into underlying database abstractions. Hence the error.
I agree, quite not descriptive, hope they will fix that in future versions.
So try to search for properties of object type and check, are they used as keys, if yes, try to replace them with specific types supported by your database provider.
Reported error for developers: #9817.

Entity Framework {"Specified argument was out of the range of valid values.\r\nParameter name: name"}

HI I am getting error when i try to save data to the table [ir].[InspectionQCExceptionRuleConfig]
{"Specified argument was out of the range of valid
values.\r\nParameter name: name"}
I am not sure why, I am trying to save data. But, I am able to retrieve data from the models. I pasted the code, context and domain model. If any one knows about his . Pls tell me..
public InspectionQCExceptionRuleConfig SaveInspectionQCRules
(InspectionQCExceptionRuleConfig inspectionruleconfig)
{
if (inspectionruleconfig != null)
{
try
{
using (InspRulesData ctx = new InspRulesData())
{
inspectionruleconfig = ctx.UpdateGraph(inspectionruleconfig, map => map);
//ctx.InspectionQCExceptionRuleConfigs.Add(inspectionruleconfig);
ctx.SaveChanges();
}
}
catch (DbEntityValidationException ex)
{
Logging.LogError(ex);
throw;
}
catch (Exception ex)
{
Logging.LogError(ex);
throw;
}
}
return inspectionruleconfig;
}
This is the Domain Model that is generated from Entity Framework
namespace DomainModel.FSEntity.InspRules
{
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.Spatial;
using CommonLib;
[System.CodeDom.Compiler.GeneratedCode("EF", "6.1.0")]
[Table("ir.InspectionQCExceptionRuleConfig")]
public partial class InspectionQCExceptionRuleConfig : BaseDomainModel
{
[Key]
[StringLength(50)]
[DatabaseGenerated(DatabaseGeneratedOption.None)]
public string ClientNumber { get; set; }
public bool QCOrdered { get; set; }
public bool DwellingType { get; set; }
public bool VacantToOccupied { get; set; }
public bool VacantToOccupiedWithActivePreservation { get; set; }
}
}
This is Context that is used by the Entity Framework to save the data o the table InspectionQCExceptionRuleConfig
public partial class InspRulesData : CustomDbContext
{
public InspRulesData()
: base("name=PlatformEntityData")
{
this.Configuration.LazyLoadingEnabled = false;
}
public virtual DbSet<InspectionQCExceptionRuleConfig> InspectionQCExceptionRuleConfigs { get; set; }
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Entity<InspectionQCExceptionRuleConfig>()
.Property(e => e.ClientNumber)
.IsVariableLength()
.IsUnicode(false);
}
}
It can also be caused by a misplaced [NotMapped] attribute in the Domain Model.

Categories

Resources