entity-framework-6

what are the circumstances of using .Wait() when calling async methods

六月ゝ 毕业季﹏ 提交于 2019-12-06 07:45:55
I have the following async long running method inside my asp.net mvc-5 web application :- public async Task<ScanResult> ScanAsync(string FQDN) { // sample of the operation i am doing var c = await context.SingleOrDefaultAsync(a=>a.id == 1); var list = await context.Employees.ToListAsync(); await context.SaveChangesAsync(); //etc.. } and i am using Hangfire tool which support running background jobs to call this async method on timely basis, but un-fortuntly the hangefire tool does not support calling async methods directly . so to overcome this problem i created a sync version of the above

EF in WinForms: how to filter data in BindingSource/DGW (.Local.ToBindingList())

坚强是说给别人听的谎言 提交于 2019-12-06 07:39:28
I generated an EF model (Database first) and DataSource following this tutorial http://msdn.microsoft.com/en-us/data/jj682076.aspx On my form I created BindingSource (bsUsers) and bound DataGridView to it. Here is how I load data on form startup: _myDbContext = new MyDbContext(); _myDbContext.Users.Load(); bsUsers.DataSource = _myDbContext.Users.Local.ToBindingList(); It works, I can add and modify records using DataGridView and other bound controls. But the thing I didn't figure out is how to filter data. For example I want to have textbox where I can type user name (or part of it) and it

Get field from dynamically/programatically named column name with Entity Framework

我们两清 提交于 2019-12-06 07:36:46
问题 I'm looking for a method to change column and field names dynamically/programatically; as: string iLoadProfileValue = "ColumnName"; string lastCol = DatabaseFunctions.DatabaseClient .tbl_MeterLoadProfile .OrderByDescending(a => a.MeterReadDate) .FirstOrDefault(a => a.MeterID == meterID).iLoadProfileValue; I'll change iLoadProfileValue 's value programatically. And I would like to get that column's value to lastCol variable. How can it be done? Thanks a lot. Done: Last situation like this:

Entity Framework one-to-zero-or-one foreign key association

时光毁灭记忆、已成空白 提交于 2019-12-06 07:26:48
I am in the process of changing the back-end of an existing application to use Entity Framework Code First. I've used the built-in tool in Visual Studio 2015 to generate POCO classes based on my existing database. This worked perfectly for the most part, except for two classes, with a one-to-zero-or-one relationship. These are my (simplified) classes: public class Login { [Key] [DatabaseGenerated(DatabaseGeneratedOption.Identity)] public int Id { get; set; } public int TeamMemberId { get; set; } public virtual TeamMember TeamMember { get; set; } } public class TeamMember { [Key]

EntityFramework 6 Alpha 2 & MySQL Connector/NET 6.6.4

白昼怎懂夜的黑 提交于 2019-12-06 06:54:21
问题 The 6.6.4 MySQL .NET connector apparently has support for EF6. I've upgraded from EF5 and .NET 4 to EF6 alpha2 and .NET 4.5. I've recreated the ADO.NET Entity Data Model since upgrading. Upon doing anything to the database it throws up an exception message saying; ItemModel.ssdl(2,2) : error 0152: No Entity Framework provider found for 'MySql.Data.MySqlClient' ADO.NET provider. Make sure the provider is registered in the 'entityFramework' section of the application config file. See http://go

Many-to-many without an inverse property

流过昼夜 提交于 2019-12-06 06:43:58
I want to create a many-to-many relationship in EF. Normally I would use the InverseProperty attribute, however, in this case: Role ( Id, Name, ICollection<Privilege> ) Privilege ( Id, Name ) I don't have an inverse property. How to tell EF that a privilege may be used in more than one Role? [ Currently EF puts a Role_Id column in the Privilege table. This is not what I want :-) ] Edit: I do not want to use the Fluent API, I'm looking for an attribute. modelBuilder.Entity<Role>() .HasMany(r => r.Privileges) .WithMany() // <- no parameter = no inverse property .Map(m => { m.ToTable(

Entity Framework 6.1 : The given key was not present in the dictionary

倾然丶 夕夏残阳落幕 提交于 2019-12-06 06:39:58
I have a table with some relations, the program works fine until I add a new relation between this table and customer table, the ddl for PermissionCode Table (first table) is as below: CREATE TABLE [dbo].[PermissionCode] ( [Id] int NOT NULL IDENTITY(1,1) , [Salt] varchar(3) COLLATE Turkish_CI_AS NOT NULL , [Code] nvarchar(12) COLLATE Turkish_CI_AS NOT NULL , [StartDate] date NULL , [EndDate] date NULL , [TypeId] int NOT NULL , [UserId] nvarchar(128) COLLATE Turkish_CI_AS NULL , [OwnerId] int NULL , [CategoryId] int NULL , [IsActive] bit NOT NULL DEFAULT ((1)) , [InsertIdentifier] varchar(8)

Accessing expression bodied members to build expression trees

你。 提交于 2019-12-06 06:32:49
Trying to build an order by expression using expression trees. But I am unable to access an expression bodied property of the query result's class. This is the class structure: public class AssetFileRecord : IAuditable, IEntity, INavigateToCustomValues { public AssetFileRecord() { this.UpdatedTimeStamp = DateTime.UtcNow; } public AssetFileRecord GetRecord() { return this; } public Guid Id { get; set; } public int DisplayId { get; set; } public string AssetTagNumber { get; set; } [JObjectIgnore] public virtual Account Account { get; set; } public string AccountNumber => Account?.AccountNumber;

Incorrect usage of spatial/fulltext/hash index and explicit index order EF

。_饼干妹妹 提交于 2019-12-06 05:54:07
I am getting Incorrect usage of spatial/fulltext/hash index and explicit index order this error while trying to login. I am not using Entity Framework migration. [DbConfigurationType(typeof(MySqlEFConfiguration))] public class ApplicationDbContext : IdentityDbContext<ApplicationUser> { public ApplicationDbContext() : base("DefaultConnection") { } static ApplicationDbContext() { // Set the database intializer which is run once during application start // This seeds the database with admin user credentials and admin role Database.SetInitializer<ApplicationDbContext>(new CreateDatabaseIfNotExists

Entity Framework Code First Migrations

戏子无情 提交于 2019-12-06 05:22:04
问题 on running following command pm> Update-Database getting following error System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.TypeInitializationException: The type initializer for 'System.Data.Entity.SqlServer.SqlProviderServices' threw an exception. ---> System.TypeLoadException: Method 'ExecuteAsync' in type 'System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy' from assembly 'EntityFramework.SqlServer, Version=6.0.0.0,