entity-framework-6

EF6 POCO INotifyPropertyChanged without viewmodels

為{幸葍}努か 提交于 2019-12-01 21:57:25
I have been binding in WPF application directly to the model classes (and skipping creating individual viewmodel classes). Now, after switching to EF6 and DBContext, I face an issue with the generated EF POCO classes since it looks its either kind of tricky or not even recommended trying to make INotifyPropertyChanged interface implemented directly to those classes. Currently: I don't want to go back to ObjectContext. I don't want to change T4 too much either. The suggestions on the web for changing T4 to achieve INotifyPropertyChanged looks too error-prone for me. Creating viewmodels for each

Adding Where Condition to All Requests EF6

人盡茶涼 提交于 2019-12-01 20:33:45
问题 Most of my entities (not all) have two properties called CompanyId and Deleted . How would be possible to auto insert these two properties for all select requests instead of setting manually on every single query I have along the whole app. Example: db.MyEntity.Where(me => me.Id == 1).Select(me => me.Description) Check dynamically it the entity has the props CompanyId and Deleted . Case affirmative, transform it like this db.MyEntity.Where(me => me.Id == 1 && Deleted == false && CompanyId ==

“Unknown data type” error with Firebird embedded and Entity Framework 6

时光毁灭记忆、已成空白 提交于 2019-12-01 20:19:33
I'm using an embedded Firebird database with code first (Entity Framework 6). The first time the application runs, it works fine: the database gets created and the data gets inserted. But every time it runs after that, it throws the following exception: An exception of type 'System.NotSupportedException' occurred in FirebirdSql.Data.FirebirdClient.dll but was not handled in user code Additional information: Unknown data type The project includes the following NuGet packages: EntityFramework [6.0.2] Firebird ADO.NET Data provider (Entity Framework 6) [4.1.0.0] I added the DbProviderFactories

Optional One-to-many Relationship in Entity Framework

巧了我就是萌 提交于 2019-12-01 20:18:04
问题 I'm having issues getting an optional one-to-many relationship to work. My model is: public class Person { public int Identifier { get; set; } ... public virtual Department Department { get; set; } } public class Department { public int Identifier { get; set; } ... public virtual IList<Person> Members { get; set; } } I want to assign zero or one Department to a Person . When assigned, the Person should show up in the Members -List of the Department . I'm configuring the Person using the

Entity Framework Code First MaxLength and FixedLegth (char vs varchar)

只愿长相守 提交于 2019-12-01 19:13:01
问题 I have an Entity Framework CodeFirst model that I'm creating from existing Database and I want to decorate some char and varchar in different way using DataAnnotations. Difference between char and varchar is that the Char has fixed length and varchar have variable length. For Varchar I'm using [Maxlength(length)] For char is this the correct way or there is a better way to define that the string property in the class is mapped as a char in the Database? 回答1: With the fluent api you can use

How can you add a navigation property on a view in EF 6.1 CodeFirst

こ雲淡風輕ζ 提交于 2019-12-01 18:45:09
Let's make a case to explain my problem. MyTable1 +id +myTable2Id MyTable2 +id MyView1 +id +myTable2Id MyView1 exists in the case, from data from the MyTable1. Now i want to create a Navigation property from my EF6.1 Code first approach in my View to MyTable2. I know that it was possible from the database first approach, but is it also possible from the code-first approach and how? EDIT: I search some on internet, but due many meanings of the word View, it's very hard to find information on it. Also with the approaches in codes that i tried, i always get an error that the migration can't be

EntityFramework 6 RC1 Include on Many-to-Many property fails

房东的猫 提交于 2019-12-01 18:08:28
I have a many-to-many relationship between Agents and AgentGroups (psuedocode, abbreviated). public class Agent { public virtual List<AgentGroup> AgentGroups { get; set; } } public class AgentGroup { public virtual List<Agent> Agents { get; set; } } At some point in the code, I want to get all AgentGroups, and I want to prefetch/include the Agents for each group. I also want to pre-fill the AgentGroups collection on the Agents. This was working in EF 6 beta, but no longer works in EF 6 rc1: List<AgentGroup> allGroups = context.AgentGroups.Include("Agents").Include("Agents.AgentGroups").ToList(

Entity Framework 6 with SQL Server 2012 gives System.Data.Entity.Core.ProviderIncompatibleException

醉酒当歌 提交于 2019-12-01 17:46:21
I have Visual Studio 2012 and I'm using the Entity Framework stack with EF 6. I did all correct but while adding migration I am getting the error . System.Data.Entity.Core.ProviderIncompatibleException Here are the classes public class Order { public virtual int OrderID { get; set; } } The context file public ShoppingCartContext() : base("ShoppingCartDb") { Database.SetInitializer<ShoppingCartContext>(new DropCreateDatabaseAlways<ShoppingCartContext>()); } protected override void OnModelCreating(DbModelBuilder modelBuilder) { #region Entity Framework 6 RC-1 modelBuilder.Properties().Where(x =>

TransactionScope and SQLite database gets locked

我的梦境 提交于 2019-12-01 17:23:45
I am trying to use Entity Framework 6 with SQLite and running into a database locked issue when trying to use TransactionScope . Here is my code: using (var txn = new TransactionScope()) { using (var ctx = new CalibreContext()) { var book = ctx.Books.First(x => x.Id == 2); var author = ctx.Authors.First(x => x.Id == 3); book.Authors.Add(author); ctx.SaveChanges(); } txn.Complete(); } First line var book = ctx.Books.First(x => x.Id == 2); executes ok. but then once I move on to the next one I get an exception saying that my database is locked. Here is my app config: <configuration>

Entity Framework 6 Where in Bulk Update/Delete in one transaction

余生颓废 提交于 2019-12-01 17:19:42
In EF6, I want to update/delete bulk data in one query. My code is using (var context = _dataContextFactory.GetContext()) { var result1 = from b in context.MyTables where new List<int> {592, 593, 594}.Contains(b.Id) select b; foreach (var item in result1 ) { item.StatusId = 3; } context.SaveChanges(); } But in Sql Profiler, there are three scripts exec sp_executesql N'UPDATE [dbo].[MyTable] SET [StatusId] = @0 WHERE ([Id] = @1) ',N'@0 int,@1 int',@0=1,@1=592 exec sp_executesql N'UPDATE [dbo].[MyTable] SET [StatusId] = @0 WHERE ([Id] = @1) ',N'@0 int,@1 int',@0=1,@1=593 exec sp_executesql N