entity-framework-6

Entity Framework List Contains in lambda

老子叫甜甜 提交于 2019-12-18 06:12:29
问题 I want to query items with specific IDs using. For example: var ids = new List<int> { 1, 3, 5 }; var items = context.Items.Where(item => ids.Contains(item.ID)).ToList(); Questions: Will this generate a single query with SQL IN operator? Is this code OK in terms of performance? Are there any better ways to do it? I am using Entity Framework 6 with Microsoft SQL Server. 回答1: Will this generate a single query with SQL IN operator? Yes Is this code OK in terms of performance? Yes (for small lists

UOW - A second operation started on this context before a previous asynchronous operation completed

偶尔善良 提交于 2019-12-18 05:43:45
问题 I am trying following code, it has two parts, one is navigation via prism. When navigation is allowed I am starting a deep load asynchronously but each time with a new context. In later code I would want to cancel pending navigations that are not finished this loading but the below code does not even work so cancellation is a matter for later ;-) navigation logic : no problems here public void OnNavigatedTo(NavigationContext navigationContext) { int relatieId = (int)navigationContext

The type 'Company.Model.User' and the type 'Company.Core.Model.User' both have the same simple name of 'User' and so cannot be used in the same model

旧街凉风 提交于 2019-12-18 05:27:07
问题 I have a base entity class MyCompany.Core.Model.User which is to be used for common properties of a User entity: public class User { public string Username { get; set; } public string Usercode { get; set; } } I also have a base mapping class MyCompany.Core.Model.UserMap to setup the code first mappings for the base User class: public class UserMap<TUser> : EntityMapBase<TUser> where TUser : User { public UserMap() { // Primary Key this.HasKey(t => t.Usercode); // Table & Column Mappings this

SQL column default value with Entity Framework

佐手、 提交于 2019-12-18 04:35:12
问题 I am trying to use Code-First EF6 with default SQL values. For example, I have a "CreatedDate" column/property not null with a default in SQL of "getdate()" How do I represent this in my code Model? Currently I have: <DatabaseGenerated(DatabaseGeneratedOption.Computed)> Public Property CreatedDate As DateTime Will this work, or will I need to use a nullable even though the actual column should be not null, so EF doesn't send a value when it hasn't been set: <DatabaseGenerated

EF6, SQLite won't work without App.config

独自空忆成欢 提交于 2019-12-18 04:33:23
问题 I'm trying to make a plug in that will use EF6.1 and SQLite for an app where I can't change the App.config so all the configuration and connection string needs to be set in code. I found this answer that looked promising Problems using Entity Framework 6 and SQLite So now I have a configuration class like this: public class CollectionDbConfiguration : DbConfiguration { public CollectionDbConfiguration() { SetProviderServices("System.Data.SQLite"(DbProviderServices)SQLiteProviderFactory

Entity Framework 6 and SQL Server Sequences

萝らか妹 提交于 2019-12-18 03:16:14
问题 I am using EF6 with a database first project. We have a requirement to use sequences which was a feature introduced in SQL server 2012 (I believe). On the table the identity column has a default value set using: (NEXT VALUE FOR [ExhibitIdentity]) This is used as we have two tables which store exhibit information for separate departments but we need the identity to be unique across both of the tables as it is then used as a reference in lots of other shared common tables. My problem is using

What is the benefit to using await with an async database call

南笙酒味 提交于 2019-12-18 02:40:09
问题 I am just looking at the default MVC5 project and how it uses async in the controllers. I would like to know what benefit async provides here over simply using synchronous calls: [HttpPost] [ValidateAntiForgeryToken] public async Task<ActionResult> Disassociate(string loginProvider, string providerKey) { ManageMessageId? message = null; //why use an async database call here with await instead of just using a synchronous one? IdentityResult result = await UserManager.RemoveLoginAsync(User

Generic repository to update an entire aggregate

血红的双手。 提交于 2019-12-17 22:51:37
问题 I am using the repository pattern to provide access to and saving of my aggregates. The problem is the updating of aggregates which consist of a relationship of entities. For example, take the Order and OrderItem relationship. The aggregate root is Order which manages its own OrderItem collection. An OrderRepository would thus be responsible for updating the whole aggregate (there would be no OrderItemRepository ). Data persistence is handled using Entity Framework 6. Update repository method

Entity framework nested projections are slow

不羁的心 提交于 2019-12-17 20:55:20
问题 I'm running a query to fetch a users profile. The query get the users details, as well as all the reviews they have posted, as well as the comments in the reviews. It may well be a case of I'm trying to get back too much, but as the api is getting called from mobile, I'd rather get as much as I can in one network call rather than making multiple network calls. At the moment this is generating some really long sql, and takes around 25 seconds! Any tips on how to improve it, or whether

The provider for the source IQueryable doesn't implement IAsyncQueryProvider

六月ゝ 毕业季﹏ 提交于 2019-12-17 20:47:05
问题 I have some codes like below, I want to write unit tests my method. But I'm stuck in async methods. Can you help me please ? public class Panel { public int Id { get; set; } [Required] public double Latitude { get; set; } public double Longitude { get; set; } [Required] public string Serial { get; set; } public string Brand { get; set; } } public class CrossSolarDbContext : DbContext { public CrossSolarDbContext() { } public CrossSolarDbContext(DbContextOptions<CrossSolarDbContext> options) :