entity-framework-6

Code First migration from int to Guid primary key issue

孤街浪徒 提交于 2020-01-13 10:15:47
问题 I'm trying to change my code first ID column from 'int' to 'Guid', and when trying to run the migration, I get the message: Identity column 'CustomFieldId' must be of data type int, bigint, smallint, tinyint, or decimal or numeric with a scale of 0, and constrained to be nonnullable. I'm defining the column like this: public partial class CustomField : BaseEntity { [Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)] public Guid CustomFieldId { get; set; } Mapping it in

Unable to update EntityFramework models from MySQL database in Visual Studio 2015 RC

时间秒杀一切 提交于 2020-01-13 08:22:08
问题 My organization upgraded from Visual Studio 2013 to Visual Studio 2015 RC a couple months ago, and we only just now attempted to update some of our existing "db-first" EntityFramework models from our MySQL database. When doing so, we received the following error. An exception of type 'System.ArgumentException' occurred while attempting to update from the database. The exception message is: 'Unable to convert runtime connection string to its design-time equivalent. The libraries required to

AspNet.Identity Custom User and Custom Role should be simple; what am I missing?

偶尔善良 提交于 2020-01-13 03:53:09
问题 Using examples from http://www.asp.net/identity I've gotten this far. The RoleManager works flawlessly and I treat the UserManager the same. I think everything is correct, but I can't seem to new up a UserManager correctly in a controller. What is wrong? At one point, I was successfully getting the UserManager to work but was getting an EntityValidationError saying "Id is required" when creating a new user with UserManager.Create(user, password); as posted in this question UserManager.Create

How do I create connection string programmatically to MS SQL in Entity Framework 6?

橙三吉。 提交于 2020-01-12 06:58:27
问题 How do I create connection string programmatically to MS SQL in Entity Framework 6? I'm using c# and WPF and I was wondering if someone could show me how or link me to a resource that shows how to set up connection strings programmatically in EF 6. The MSDN article explains that you can http://msdn.microsoft.com/en-us/data/jj680699#moving but it doesn't go into creating actual connection strings. So here is an EF6 example that works App.Config entityFramework codeConfigurationType="WPFwithEF

Entity Framework and OFFSET/FETCH on Sql Server

自作多情 提交于 2020-01-11 10:36:29
问题 I just encountered a weird bug in my app where a paged data grid contained duplicate rows. Investigation showed that it's because the new paging mechanism Entity Framework uses with Sql Server 2012 as of version 6.1.2 only works on strictly ordered column sets , as is documented here. Since most columns are not strictly ordered (meaning you have duplicate entries with respect to the sort order), simply binding one of the typical grid middlewares to Entity Framework is now broken subtly and

Entity Framework and OFFSET/FETCH on Sql Server

半世苍凉 提交于 2020-01-11 10:36:13
问题 I just encountered a weird bug in my app where a paged data grid contained duplicate rows. Investigation showed that it's because the new paging mechanism Entity Framework uses with Sql Server 2012 as of version 6.1.2 only works on strictly ordered column sets , as is documented here. Since most columns are not strictly ordered (meaning you have duplicate entries with respect to the sort order), simply binding one of the typical grid middlewares to Entity Framework is now broken subtly and

ADO.NET provider with invariant name 'System.Data.SqlClient;' cannot be found (Entity Framework MVC)

老子叫甜甜 提交于 2020-01-11 09:19:47
问题 I cannot seem to resolve what appears to be a common issue with Entity Framework 6. I have reviewed the many topics related to this issue on SO, and am unable to find a solution that works for my particular case. I have up until this point been developing using localdb with code first migrations, which worked fine. But now that I am moving this to a actual SQL server instance it throws the following error while attempting migrations: "The ADO.NET provider with invariant name 'System.Data

Multiple .Where() clauses on an Entity Framework Queryable

送分小仙女□ 提交于 2020-01-11 08:34:10
问题 I am trying to implement a complex filter using Entity Framework: I want to add where clauses to the queryable object based on my provided search criteria. Can I do the following in Entity Framework 6? var queryable = db.Users.Where(x => x.Enabled && !x.Deleted); // Filter var userId = User.Identity.GetUserId(); queryable.Where(x => x.AspNetUser.Id == userId); queryable.Where(x => x.Status >= 2); // ...etc I know that I can do: var queryable = db.Users .Where(x => x.Enabled && !x.Deleted)

How can I set the foreign key name using the Fluent API with Code First Migrations?

爱⌒轻易说出口 提交于 2020-01-11 08:01:12
问题 I'm trying to set the foreign key name (not the foreign key column) using Code First Migrations on EF6.4. I know that it can be set by updating the generated migration code, like so: .ForeignKey("Documents", Function(t) t.DocumentId, cascadeDelete:=True, name:="FK_Sections_Documents") ...but I'd like to do it before the migration is added, using the Fluent API. I seem to recall something about the HasForeignKey() call accepting a Func that contains a call to an anonymous type in its body,

IManifestTokenResolver for Database First Model?

落爺英雄遲暮 提交于 2020-01-11 07:22:07
问题 We need an option to set the ProviderManifestToken in code for a Database First Model in order to override the value from the EDMX, which defaults to "2012" for SQL Server 2012 in our particular case. What we've tried so far: As described in this post we decorated our context class with the DbConfigurationType attribute, our derived class looks exactly the same as in that post. internal sealed class MyDbConfiguration : DbConfiguration { public MyDbConfiguration() { //this