entity-framework-6

error loading database initializer with EF6

早过忘川 提交于 2019-11-30 08:33:32
I have been trying to follow this tutorial ... http://www.asp.net/mvc/tutorials/getting-started-with-ef-using-mvc/creating-an-entity-framework-data-model-for-an-asp-net-mvc-application but I keep getting the following error ... system.invalidoperationexception = {"Failed to set database initializer of type 'WeddingPreparations.Dal.WeddingInitializer, KevinLisaWedding' for DbContext type 'WeddingPreparations.Dal.WeddingContext' specified in the application configuration. See inner exception for details."} The inner exception is ... {"Could not load type 'WeddingPreparations.Dal.WeddingContext'

In Entity Framework 6.1 (not Core), how can I use the IndexAttribute to define a clustered index?

你离开我真会死。 提交于 2019-11-30 08:14:14
Entity Framework 6.1 (code-first) has added the possibility of adding indexes via the IndexAttribute . The attribute takes a parameter for specifying whether the index should be clustered or non-clustered. At the same time, AFAIK, Entity Framework requires every entity to have a primary key (annotated with the KeyAttribute ), and that primary key is always created as a clustered key. Therefore, as soon as I apply the IndexAttribute with IsClustered = true , I get an error because, due to the key, there already is a clustered index. So, how can I create a clustered index that is not the primary

Unable to determine the provider name for provider factory of type 'System.Data.SQLite.SQLiteFactory'. with the Nuget package version 1.0.94.1

风格不统一 提交于 2019-11-30 08:11:54
I am getting this error with the Nuget package for SQLite 1.0.94.1. I fiddled around with the various app.config sections, helped by similar questions about previous versions of this package, but I cannot get it to work. Below is the app.config as I found it after installing the Nuget package. I deleted the app.config prior to installing it. I only added the connectionstrings after that. So, where is the problem?? <?xml version="1.0" encoding="utf-8"?> <configuration> <configSections> <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection,

FindAsync and Include LINQ statements

左心房为你撑大大i 提交于 2019-11-30 07:47:54
问题 The code I have got so far works fine public async Task<ActionResult> Details(Guid? id) { if (id == null) { return new HttpStatusCodeResult(HttpStatusCode.BadRequest); } ItemDetailModel model = new ItemDetailModel(); model.Item = await db.Items.FindAsync(id); if (model.Item == null) { return HttpNotFound(); } return View(model); } But I want to include 1 table more and cannot use FindAsync public async Task<ActionResult> Details(Guid? id) { if (id == null) { return new HttpStatusCodeResult

Entity Framework auto increment with starting value

▼魔方 西西 提交于 2019-11-30 07:39:06
问题 I have a entity as follows [Table("ESS_POS_SE_VERSION")] public class Version { [Key, Column("DETAIL_ID"), DatabaseGenerated(DatabaseGeneratedOption.Identity)] public int Id { get; set; } [Column("DETAIL_TITILE")] public string DetailKey { get; set; } [Column("DETAIL")] public string Detail { get; set; } } SO Id column is auto increment column, but I need to set its starting value to 1000. How can I do it? 回答1: Consider creating a custom database initializer. It will be called each time your

How to get EF6 to honor Unique Constraint (on FK) in Association/Relationship multiplicity?

这一生的挚爱 提交于 2019-11-30 07:25:39
问题 2019 Update / TLDR; switch to Entity Framework Core (or whatever else) While missing some "Features", EF Core properly honors Alternate Keys (aka Unique Constraints) in addition to Primary Keys and thus does a much better job of honoring Relational Algebra. YMMV otherwise; at least it supports many more SQL schemes correctly. This support added was in the (very outdated) EF Core 1.0 release.. a bit disappointing that the original EF never had this design(ed!) flaw addressed. This may be

Updating existing data in EF 6 throws exception - “…entity of the same type already has the same primary key value.”

半城伤御伤魂 提交于 2019-11-30 07:24:54
I am trying to update a record using Entity Framework 6, code-first, no fluent mapping or a tool like Automapper. The entity( Employee ) has other composite properties associated with it like Addreess (collection), Department It is also inherited from a base called User The save method is as follows, with _dbContext being the DbConext implementation public bool UpdateEmployee(Employee employee) { var entity = _dbContext.Employees.Where(c => c.Id == employee.Id).AsQueryable().FirstOrDefault(); if (entity == null) { _dbContext.Employees.Add(employee); } else { _dbContext.Entry(employee).State =

EF + ODP.NET + CLOB = Value Cannot be Null - Parameter name: byteArray?

安稳与你 提交于 2019-11-30 07:11:01
问题 Our project recently updated to the newer Oracle.ManagedDataAccess DLL's (v 4.121.2.0) and this error has been cropping up intermittently. We've fixed it a few times without really knowing what we did to fix it. I'm fairly certain it's caused by CLOB fields being mapped to strings in Entity Framework, and then being selected in LINQ statements that pull entire entities instead of just a limited set of properties. Error: Value cannot be null. Parameter name: byteArray Stack Trace: at System

LINQ to Entities does not recognize the method 'System.Object GetValue(…)'

我与影子孤独终老i 提交于 2019-11-30 07:10:45
问题 My issue is I need to query on the value of a property in a generic class. The property is tagged with an attribute. See the following code: var rowKeyProperty = EFUtil.GetClassPropertyForRowKey<T>(); var tenantKeyProperty = EFUtil.GetClassPropertyForTenantKey<T>(); var queryResult = objContext.CreateObjectSet<T>().Single(l => (((int) tenantKeyProperty.GetValue(l, null)) == tenantKey) && (((int)rowKeyProperty.GetValue(l, null)) == KeyValue)); The rowKeyProperty and tenantKeyProperty are of

Entity Framework : Sharing entities across different DbContexts

余生颓废 提交于 2019-11-30 07:01:53
I'm developing a plugin application with EF6, code first. I have one main context with an entity called User : public class MainDataContext : DbContext { public MainDataContext(): base("MainDataContextCS") {} public DbSet<User> Users { get; set; } } And then another context for PluginX, on another project which references the base one: public class PluginDataContext : DbContext { public PluginDataContext () : base("MainDataContextCS") { } protected override void OnModelCreating(DbModelBuilder modelBuilder) { modelBuilder.HasDefaultSchema("PluginX"); base.OnModelCreating(modelBuilder); } public