dbcontext

Getting “The entity type <model> is not part of the model for the current context.”

ⅰ亾dé卋堺 提交于 2019-11-30 07:58:19
问题 I am having this issue updating my database 1 column at a time in asp.net using web api. I am trying to query a PUT to just update one value in the row instead of updating that one and setting the rest to null. I made a separate model outside of the controller to take in the update so I could do one at a time. When I hit this line db.Entry(user).State = EntityState.Modified; in the controller that is where it is erroring out. Any advice how I can fix this? This is my separate ViewModel I am

Convert DbContext to Datatable in Code first entity framework

允我心安 提交于 2019-11-30 07:14:42
问题 Hello I am trying to convert DbContext result to DataTable . I have one class i.e. ClientTemplateModel which inherits DbContext . In this class I have one DbSet object i.e. public virtual DbSet<imagecomment> ImageComments { get; set; } . I am using Code first entity framework . Here is my query. using (ClientTemplateModel context = new ClientTemplateModel(connectionString)) { var result = context.ImageComments.Where(p => p.Dcn == dcn).OrderByDescending(p => p.CommentsDateTime); } Here I am

Multiple DbContexts in N-Tier Application

自古美人都是妖i 提交于 2019-11-30 07:01:04
问题 I'm creating my first N-Tier MVC application and I've run into a road block with how to manage multiple DbContexts with my database first approach. I have the following layers Presentation Service (WCF) Business Data Access I don't want an entity framework reference in my service layer but I don't see how to create an Interface or something to manage two contexts. I have it working with a single context warpped in a IDatabaseFactory but I can't seem to find an approach to manage two. Below is

Using Entity Framework 6 with Multiple DB Schemas but using One DBContext

旧时模样 提交于 2019-11-30 06:42:07
问题 I have an application using EF as ORM. The database used to have one schema, dbo and everything was working fine. I recently organized my tables into 4 different schemas. Some tables of one schema have dependencies on tables that reside on a different schema. All seems to be valid on the SQL side. On the app side all db interactions through EF are not working anymore. The code compiles, the schemas are visible in the solution, the model mappings point to the right schemas, but once I try to

Multi-tenancy web application with filtered dbContext

 ̄綄美尐妖づ 提交于 2019-11-30 05:41:50
I am new to ASP.Net MVC and multi-tenancy web application. I have done lots of reading, but being a beginner I just follow what I understand. So I managed to built a sample scenario web application and need to solve the ending part of it. Hope this scenario will be useful for some other beginners as well, but would welcome any other approach. Thanks in advance 1) Database in SQLServer 2008. 2) Data layer: C# class library project called MyApplication.Data public class AppUser { [Key] public virtual int AppUserID { get; set; } [Required] public virtual int TenantID { get; set; } [Required]

Multithreading Entity Framework: The connection was not closed. The connection's current state is connecting

老子叫甜甜 提交于 2019-11-30 02:03:18
So I have a windows service process that performs a workflow process. The back end uses Repository and UnitofWork Pattern and Unity on top of Entity Framework with the entities class generated from the edmx. I won't go into a whole lot of detail as its not necessary but basically there are 5 steps that the workflow goes through. A particular process might be at any stage at any point in time (in order of course). Step one just generates data for step two, which validates the data via a long running process to another server. Then step there generates a pdf with that data. For each stage we

Using TransactionScope with Entity Framework 6

五迷三道 提交于 2019-11-30 01:47:27
What I can't understand is if its possible to make changes to the context and get the changes in the same transaction before its commited. This is what I´m looking for: using (var scope = new TransactionScope(TransactionScopeOption.Required)) { using (var context = new DbContext()) { //first I want to update an item in the context, not to the db Item thisItem = context.Items.First(); thisItem.Name = "Update name"; context.SaveChanges(); //Save change to this context //then I want to do a query on the updated item on the current context, not against the db Item thisUpdatedItem = context.Items

EF and repository pattern - ending up with multiple DbContexts in one controller - any issues (performance, data integrity)?

天大地大妈咪最大 提交于 2019-11-30 00:56:11
Most of my knowledge of ASP.NET MVC 3 comes from reading through the book Pro ASP.NET MVC 3 Framework by Adam Freeman and Steven Senderson. For my test application I have tried to stick to their examples very closely. I am using the repository pattern plus Ninject and Moq which means that unit testing work quite well (i.e. without needing to pull data from the database). In the book repositories are used like this: public class EFDbTestChildRepository { private EFDbContext context = new EFDbContext(); public IQueryable<TestChild> TestChildren { get { return context.TestChildren; } } public

Entity Framework code first: How to ignore classes

耗尽温柔 提交于 2019-11-29 17:38:22
问题 This is similar to questions here and here, but those are old and have no good answers. Let's say I have the following classes: class HairCutStyle { public int ID { get; set; } public string Name { get; set; } } class CustomerHairCutPreference { public int ID { get; set; } public Customer Customer { get; set; } public HairCutStyle HairCutStyle { get; set; } } Let's say my HairCutStyle data is stored in a table in another database (I get it from Paul Mitchell himself). I want to use the

How to return dynamic object from SQL query

六月ゝ 毕业季﹏ 提交于 2019-11-29 16:24:50
I have situation where a storeprocdure return collection, but I do not how the object structure because the query is very dynamic. One query can return: Id | Location | MarketSegment | ... n columns and another can return Id | Sales Rep | Location | Region | ... n columns I am simply just return a "object" as you can see in the code below. I know this won't work, but how can I set it up so it does? using (DbContext db = new Context()) { var items = db.Database.SqlQuery<object>( "SP @Param1, @Param2", new SqlParameter("Param1", ped), new SqlParameter("Param2", 25) ).ToList(); return Request