entity-framework-6

The ADO.NET provider with invariant name 'MySql.Data.MySqlClient' is either not registered in the machine or application config file

我们两清 提交于 2019-12-01 02:44:54
I have an asp.net solution using entity framework 6 to mysql server. now I have to work on that solution on a new machine, but I have some problems: 1) when building the solution I get error: "The ADO.NET provider with invariant name 'MySql.Data.MySqlClient' is either not registered in the machine or application config file". App.config: <entityFramework> <providers> <provider invariantName="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity.EF6, Version=6.9.9.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d"></provider> </providers> <

Resolving 'No key Defined' errors while using OnModelCreating with ApplicationDbContext?

99封情书 提交于 2019-12-01 02:39:56
问题 I've been trying to create navigation properties for my collection types and I found this example of how one person accomplished it using OnModelCreating. I gave it a try in my MVC 5 application and I recieved this error when trying to update my database: One or more validation errors were detected during model generation: BlogEngine.Models.IdentityUserLogin: : EntityType 'IdentityUserLogin' has no key defined. Define the key for this EntityType. BlogEngine.Models.IdentityUserRole: :

How to find a date with a list of specified date ranges in Entity Framework?

£可爱£侵袭症+ 提交于 2019-12-01 01:23:12
I have an IEnumerable of a class that I created to contain date ranges. That class looks like this: public class Range<T> where T: struct { public T Start { get; set; } public T End { get; set; } } I want to find all the records in my set where a date column falls within ANY of the specified date ranges. This was my attempt: deals = deals.Where( deal => criteria.DateRanges.Any( dt => deal.CloseDate >= dt.Start && deal.CloseDate < dt.End.Value.AddDays(1))); This throws an error I assume because EF doesn't know how to translate criteria.DateRanges.Any() to SQL. So how would you write this to

Razor Syntax gives errors in View before compiling (No intellisense)

為{幸葍}努か 提交于 2019-12-01 00:48:46
问题 I was going through the list of NuGet Packages and I was updating everything things like bootstrap, jQuery, etc. but while I was doing that, I unthinkingly updated Microsoft.Owin and another package (might have been EF or something else) and it was a major version update...woops. I had to jump through hoops by deleting my project, getting an older version from source control and getting everything back to the right versions. Everything is back to normal and I have one last issue. Razor Syntax

Many to Many relationship in Asp.Net MVC 5 with Identity table and Custom table

*爱你&永不变心* 提交于 2019-12-01 00:18:23
I'm trying to make a relationship between the Users from the table generated by Asp.Net Identity with my own table. The relationship must be many to many, since many Users can work on the same Task (which is my table), and same time an User can work on multiple Tasks. public class Task { public int ID { get; set; } public string Name { get; set; } public string UserID { get; set; } public virtual ICollection<ApplicationUser> Users { get; set; } } public class ApplicationUser : IdentityUser { public int TaskID { get; set; } public virtual ICollection<Task> Tasks{ get; set; } // rest of the code

Entity Framework - ridiculous Query, casting smallint to int for comparison [duplicate]

一笑奈何 提交于 2019-12-01 00:13:51
问题 This question already has answers here : Generated query for tinyint column introduces a CAST to int (9 answers) Closed 5 years ago . Out of ideas here. I have a simple table that is model first mapped with Entity Framework and I get the following SQL generated: (@p__linq__0 int,@p__linq__1 int)SELECT [Extent1].[BucketRef] AS [BucketRef], [Extent1].[VariantNo] AS [VariantNo], [Extent1].[SliceNo] AS [SliceNo], [Extent1].[TradeNo] AS [TradeNo], [Extent1].[TradeBegin] AS [TradeBegin], [Extent1].

EF Code First - Invalid column name

折月煮酒 提交于 2019-11-30 23:50:26
问题 Im getting an error "Invalid column name 'FeeLevel_LevelId' which makes absolutely no sense considering all properties are simple types and there is no FeeLevel nor a LevelId object in this object. So my context is: public partial class FeesDbContext : DisconnectedEntityContext { public DbSet<Currency> Currencies { get; set; } public DbSet<FeeLevel> FeeLevels { get; set; } public DbSet<FeeLevelDetail> FeeLevelDetails { get; set; } public DbSet<FeeType> FeeTypes { get; set; } public DbSet

Entity Framework Poor COUNT Performance

人盡茶涼 提交于 2019-11-30 22:23:17
We are experiencing very poor performance using Entity Framework 5.0 with MySql Connector 6.6.6.0 for count based queries. Our data structure looks like: Table: Post =========== ID INT PRIMARY KEY MemberID INT NOT NULL SiteID INT NOT NULL Description VARCHAR(255) NOT NULL Image VARCHAR(255) NOT NULL CreatedDate DATETIME NULL And using entity framework with a linq query like the following: var count = entities.Post.Where(p => p.SiteID == 1 && p.CreatedDate != null).Count(); We get the following generated SQL: SELECT `Extent1`.`ID`, `Extent1`.`MemberID`, `Extent1`.`SiteID`, `Extent1`.

Polymorphic Associations in Entity Framework

最后都变了- 提交于 2019-11-30 21:03:59
问题 I have a legacy database that has a few tables which were designed using Polymorphic Associations. By polymorphic associations, I mean that those tables can be child of different tables according to a column ObjectType . Example: Documents table has DocumentID (identity primary key), some other columns, and 2 special columns called ObjectType and ObjectID . If ObjectType='STUDENT' , ObjectID points to Students table. If ObjectType='TEACHER' , ObjectID points to Teachers table, etc. This is

Entity Framework include filter child collection

心已入冬 提交于 2019-11-30 19:38:47
I have some difficulty to add some filter condition for included items in my LINQ query. My query is like var item = _Context.Order.Include("Inner") .Include("Inner.first") .Include("Inner.second") .Where(x => ( !(x.IsDeleted) && (x.IsActive) && (x.itemid == id))).FirstOrDefault(); In the above code "Inner" is another list of item. Now i need to filter inner items. I only need inner item with filter condition inner.isDeleted = true. Query should return a class like, public class Order { public string Name { get; set; } public List<InnerDetails> Inner{ get; set; } public bool IsDeleted { get;