entity-framework

How can I return the ID of the Inserted Record in Entity Framework Generic Insert Method?

主宰稳场 提交于 2020-08-27 12:57:06
问题 Here is the generic insert method. I need your suggestion to return the ID of the inserted record. public static void Create<T>(T entity) where T : class { using (var context = new InformasoftEntities()) { DbSet dbSet = context.Set<T>(); dbSet.Add(entity); context.SaveChanges(); } } 回答1: You need a little modification: You need to create an IHasAutoID that implemented by Entity public interface IHasAutoID { int getAutoId(); } In Entity Class public class EntityA : IHasAutoID { public int

How can I return the ID of the Inserted Record in Entity Framework Generic Insert Method?

与世无争的帅哥 提交于 2020-08-27 12:45:12
问题 Here is the generic insert method. I need your suggestion to return the ID of the inserted record. public static void Create<T>(T entity) where T : class { using (var context = new InformasoftEntities()) { DbSet dbSet = context.Set<T>(); dbSet.Add(entity); context.SaveChanges(); } } 回答1: You need a little modification: You need to create an IHasAutoID that implemented by Entity public interface IHasAutoID { int getAutoId(); } In Entity Class public class EntityA : IHasAutoID { public int

How to know project is code-first or database-first?

十年热恋 提交于 2020-08-27 07:38:40
问题 In an existing project, how do I know if it's code-first or database-first? Project has this lines of code: public class TestDBContext : DbContext { public DbSet<Player> Players { get; set; } protected override void OnModelCreating(DbModelBuilder modelBuilder) { modelBuilder.Conventions.Remove<PluralizingTableNameConvention>(); } } And project has no .edmx file. If any other details need I will share. EDIT: Player.cs class public class Player { public int PlayerID { get; set; } public string

How to Except Property instead of Select in Lambda LINQ

自闭症网瘾萝莉.ら 提交于 2020-08-25 05:09:29
问题 I have a code that fetching a table. Here's my sample code: public IQueryable<MyItem> MyItems(){ return context.MyItem; } Here are the sample properties of MyItem public int Id {get;set;} public byte[] Image {get;set;} public string Name {get;set;} Since, byte[] can have multiple characters, I don't want to include then in searching because it will take so long if I have a records like 10,000 items. Typically, I would Select like this: public IQueryable<MyItem> MyItems(){ return context

Entity Framework conflict with same table name from different databases

狂风中的少年 提交于 2020-08-24 10:18:52
问题 I am using Entity Framework 4 with MVC 3 in Visual Studio 2012 (C#). I am using database first ; there are two separate databases each with its own namespace and with two separate edmx files. Each database has a table with the same name and fields (but different content). When I added the second table I started to get compile errors. Ambiguity between 'Interface.CodeFormStatus.FormStatusCodeID' and 'Interface.CodeFormStatus.FormStatusCodeID' There seem to be some complex workarounds or I

Difference between PredicateBuilder<True> and PredicateBuilder<False>?

半城伤御伤魂 提交于 2020-08-24 05:32:10
问题 I have the code: var predicate = PredicateBuilder.True<Value>(); predicate = predicate.And(x => x.value1 == "1"); predicate = predicate.And(x => x.value2 == "2"); var vals = Value.AsExpandable().Where(predicate).ToList(); If I have PredicateBuilder.True<Value>() , it brings back what I expect, but if I have PredicateBuilder.False<Value>() , it brings back 0 records. Can someone explain what the the difference is and why in one scenario I get back 0 records an in the other I get what I expect.

Difference between PredicateBuilder<True> and PredicateBuilder<False>?

我只是一个虾纸丫 提交于 2020-08-24 05:30:06
问题 I have the code: var predicate = PredicateBuilder.True<Value>(); predicate = predicate.And(x => x.value1 == "1"); predicate = predicate.And(x => x.value2 == "2"); var vals = Value.AsExpandable().Where(predicate).ToList(); If I have PredicateBuilder.True<Value>() , it brings back what I expect, but if I have PredicateBuilder.False<Value>() , it brings back 0 records. Can someone explain what the the difference is and why in one scenario I get back 0 records an in the other I get what I expect.

IdentityServer4 storing Client Secrets

你离开我真会死。 提交于 2020-08-23 12:59:50
问题 I'm currently trying to build an single sign-on Server for a couple of clients to use. Because I don't exactly know, how many clients that will be, I planned to make it so I can add clients at runtime using the EntityFramework Configuration Store. My problem is now how to set the client secrets. I tried generating a new GUID and using that as a secret. The problem now is, that the Configuration Store just wants to save the hashed version of the secret and I would need to access the plain

IdentityServer4 storing Client Secrets

家住魔仙堡 提交于 2020-08-23 12:57:29
问题 I'm currently trying to build an single sign-on Server for a couple of clients to use. Because I don't exactly know, how many clients that will be, I planned to make it so I can add clients at runtime using the EntityFramework Configuration Store. My problem is now how to set the client secrets. I tried generating a new GUID and using that as a secret. The problem now is, that the Configuration Store just wants to save the hashed version of the secret and I would need to access the plain