entity-framework

Can we use enums as typesafe entity ids?

僤鯓⒐⒋嵵緔 提交于 2020-01-31 03:11:13
问题 We are working with a rather large model in a EF 6.1 code first setup and we are using ints for entity ids. Unfortunately, this is not as typesafe as we would like, since one can easily mix up ids, for example comparing ids of entities of different types (myblog.Id == somePost.Id) or similar. Or even worse: myBlog.Id++. Therefore, I came up with the idea of using typed ids, so you cannot mix up ids. So we need a BlogId type for our blog entity. Now, the obvious choice would be to use an int

Can we use enums as typesafe entity ids?

家住魔仙堡 提交于 2020-01-31 03:10:30
问题 We are working with a rather large model in a EF 6.1 code first setup and we are using ints for entity ids. Unfortunately, this is not as typesafe as we would like, since one can easily mix up ids, for example comparing ids of entities of different types (myblog.Id == somePost.Id) or similar. Or even worse: myBlog.Id++. Therefore, I came up with the idea of using typed ids, so you cannot mix up ids. So we need a BlogId type for our blog entity. Now, the obvious choice would be to use an int

Find a specified generic DbSet in a DbContext dynamically when I have an entity

若如初见. 提交于 2020-01-30 19:36:49
问题 I have following classes and DbContext : public class Order:BaseEntity { public Number {get; set;} } Product:BaseEntity; { public Name {get; set;} } public class Context : DbContext { .... public DbSet<Order> Orders { set; get; } public DbSet<Product> Products { set; get; } .... } I have a list of objects that want to add to my context, too, but I don't know how can I find appropriate generic DbSet according each entity type dynamically. IList<BaseEntity> list = new List<BaseEntity>(); Order

How to generate stored procedures as async methods through EF in c# application?

会有一股神秘感。 提交于 2020-01-30 10:53:33
问题 I've bunch of SPs that are used for invocation from my c# console application. So, I'm using EF "data base first" approach, which is rather convinient for me, because EF generates SP invokation code by itself and I'm not bothered with writing sql code like "EXEC sp...", wrapping my parameters and so on. The only problem is the next: EF generates synchronous versions of methods. And I'm wondering if there is a way to tell EF to generate asynchronous methods? Do we have any alternative

How to generate stored procedures as async methods through EF in c# application?

对着背影说爱祢 提交于 2020-01-30 10:53:25
问题 I've bunch of SPs that are used for invocation from my c# console application. So, I'm using EF "data base first" approach, which is rather convinient for me, because EF generates SP invokation code by itself and I'm not bothered with writing sql code like "EXEC sp...", wrapping my parameters and so on. The only problem is the next: EF generates synchronous versions of methods. And I'm wondering if there is a way to tell EF to generate asynchronous methods? Do we have any alternative

Entity Framework - How to clear connection pool manually? SNIX_Excecute Error

十年热恋 提交于 2020-01-30 09:22:06
问题 I'm using entity framework for a xamarin project. When the app is minimised on iOS and then opened again it throws connection problems (See error below): SNIX_Execute (provider: SNI_PN7, error: 35 - SNI_ERROR_35) The only way I've found to solve this is to set pooling to false in the connection string. I want to clear the connection pool manually in the OnSleep() method in xamarin. Is there anyway to clear Entity Framework's connection pool? 回答1: Update - Just found out how to do it. On the

LINQ where condition with dynamic column

一曲冷凌霜 提交于 2020-01-30 06:56:05
问题 I have this code // IQueryable<General> query if (columnName == "Column1") { query = query.Where(x => x.Column1 == searchValue); } else if (columnName == "Column2") { query = query.Where(x => x.Column2 == searchValue); } else if (columnName == "Column3") { query = query.Where(x => x.Column3 == searchValue); } else if (columnName == "Column4") { query = query.Where(x => x.Column4 == searchValue); } // next zilions columns to come // ... and my question is. How can i past x.Column as a

EF Code First: Retrieving a base type queries all derived type tables

安稳与你 提交于 2020-01-30 06:49:27
问题 I'm having an odd issue with EF 4.1 Code First where even though I have configured an entity to generate columns for its inherited properties, it still joins to the inherited type's table. Here are my classes: public class Human { public int Id { get; set; } public string Name { get; set; } } public class SuperHuman : Human { public int Id { get; set; } public string Powers { get; set; } } public class MarvelDbContext : DbContext { public DbSet<Human> Humans { get; set; } public DbSet

EF Code First: Retrieving a base type queries all derived type tables

試著忘記壹切 提交于 2020-01-30 06:48:26
问题 I'm having an odd issue with EF 4.1 Code First where even though I have configured an entity to generate columns for its inherited properties, it still joins to the inherited type's table. Here are my classes: public class Human { public int Id { get; set; } public string Name { get; set; } } public class SuperHuman : Human { public int Id { get; set; } public string Powers { get; set; } } public class MarvelDbContext : DbContext { public DbSet<Human> Humans { get; set; } public DbSet

linq query anonymous type cannot be converted to POCO object

半腔热情 提交于 2020-01-30 04:41:09
问题 I have the following linq query ... public List<UserProject> GetProjectsByUser(int userid) { //var query = return ( from p in this.Entities.Projects join c in this.Entities.Categories on p.CategoryId equals c.CategoryId join u in this.Entities.Users on p.UserId equals u.UserId where p.UserId == 11 select new { p.ProjectId, u.UserName, p.UserId, ProjectName = p.Name, ProjectDescription = p.Description, CategoryName = c.Name } into pcup join m in this.Entities.Messages on pcup.ProjectId equals