entity-framework-core

Xamarin Forms, Sqlite, EF Core 3, migrations, and lot of confussion

孤街醉人 提交于 2021-02-18 07:56:25
问题 I have a Xamarin Forms app that I have switched from using only restful API to using local SQLite DB, that will sync using this Dotmim.Sync - DB Sync'ing Framework (which is great!). I am using EF Core 3 in the Xamarin forms project to interact with SQLite. My questions are around running migrations or just database updates on SQLite. I have read several blogs and forums about different approaches, but they all are several years old, from EF Core 1 to EF Core 2, and lots of work around. https

EF Core - adding/updating entity and adding/updating/removing child entities in one request

|▌冷眼眸甩不掉的悲伤 提交于 2021-02-17 21:00:18
问题 I am struggling with what seemed to be a couple of basic operations. Let's say I've got a class named Master: public class Master { public Master() { Children = new List<Child>(); } public int Id { get; set; } public string SomeProperty { get; set; } [ForeignKey("SuperMasterId")] public SuperMaster SuperMaster { get; set; } public int SuperMasterId { get; set; } public ICollection<Child> Children { get; set; } } public class Child { public int Id { get; set; } public string SomeDescription {

How to remove trailing spaces and change encoding in char(n) columns in dynamic ExecuteQuery

流过昼夜 提交于 2021-02-17 07:07:21
问题 ASP.NET MVC Core 5 application uses Npgsql to get data from Postgres database. Columns in database are defined as CHAR(n) type, like: create table prpalk ( sfirmanimi char(100) ); Column types cannot be changed to varchar. Postgres database encoding is unicode. However some columns are in custom encoding which needs to be converted to unicode to be used in .NET. Those column names in database start always with word Custom. I tried Dapper to get data but data contains trailing spaces and

How to remove trailing spaces and change encoding in char(n) columns in dynamic ExecuteQuery

a 夏天 提交于 2021-02-17 07:06:15
问题 ASP.NET MVC Core 5 application uses Npgsql to get data from Postgres database. Columns in database are defined as CHAR(n) type, like: create table prpalk ( sfirmanimi char(100) ); Column types cannot be changed to varchar. Postgres database encoding is unicode. However some columns are in custom encoding which needs to be converted to unicode to be used in .NET. Those column names in database start always with word Custom. I tried Dapper to get data but data contains trailing spaces and

Get Distinct Entries Based On Specific Column in Entity Framework

感情迁移 提交于 2021-02-17 05:57:21
问题 I have a SQLite table that contains every test result we've run, and I'm looking to write an entity framework query that returns only the most recent test result per project. Normally, I'd assume this would be "group by project id, return row with the max updated value," or, alternatively, "sort by date and return first". However, when I try the query, I keep getting Entity Framework "could not be translated" errors. Here's what I've tried: results = await _context.Results .Include(x => x

Get Distinct Entries Based On Specific Column in Entity Framework

只愿长相守 提交于 2021-02-17 05:57:08
问题 I have a SQLite table that contains every test result we've run, and I'm looking to write an entity framework query that returns only the most recent test result per project. Normally, I'd assume this would be "group by project id, return row with the max updated value," or, alternatively, "sort by date and return first". However, when I try the query, I keep getting Entity Framework "could not be translated" errors. Here's what I've tried: results = await _context.Results .Include(x => x

The filter expression cannot be specified for entity type. A filter may only be applied to the root entity type in a hierarchy

假如想象 提交于 2021-02-17 05:19:26
问题 I am having trouble with this error when Adding new migration. The filter expression 'e => Not(e.IsDeleted)' cannot be specified for entity type 'Babysitter'. A filter may only be applied to the root entity type in a hierarchy. What I am doing is that I have 2 classes Babysitter and Parent that both need to be ApplicationUsers, because they have different properties. So I made them inherit the ApplicationUser class and extended them. This is the ApplicationUser class. public class

EF Core Many-to-Many self join

吃可爱长大的小学妹 提交于 2021-02-16 21:04:57
问题 I am trying to describe a many-to-many self-referential relationship to Entity Framework Core 2. Essentially what I'm trying to model is a sort of tree structure, in which each element can have an arbitrary number of parent and child elements (so I guess more a graph than a tree). Here's what I have so far: public class OrgLevel { ... public ICollection<OrgLevelOrgLevels> OrgLevelOrgLevelsAsParent { get; set; } public ICollection<OrgLevelOrgLevels> OrgLevelOrgLevelsAsChild { get; set; }

EF Core Many-to-Many self join

北慕城南 提交于 2021-02-16 21:03:38
问题 I am trying to describe a many-to-many self-referential relationship to Entity Framework Core 2. Essentially what I'm trying to model is a sort of tree structure, in which each element can have an arbitrary number of parent and child elements (so I guess more a graph than a tree). Here's what I have so far: public class OrgLevel { ... public ICollection<OrgLevelOrgLevels> OrgLevelOrgLevelsAsParent { get; set; } public ICollection<OrgLevelOrgLevels> OrgLevelOrgLevelsAsChild { get; set; }

SQL Server LocalDB instance fails to start (automatically)

若如初见. 提交于 2021-02-16 21:02:35
问题 I have a WPF application which is connecting to the SQL Server 2014 Express LocalDB (i.e. a local .mdf database file). The application uses the Entity Framework Core library version 7.0.0-rc1-final. This is the connection string that I am using: data source=(LocalDb)\InstanceLocalDB; Initial Catalog = MyAppDB; Integrated Security=True; MultipleActiveResultSets=True; Connection Timeout = 10 I do the installation of the SQL Server LocalDB during the application's setup. The same goes for the