entity-framework

How to handle many to many same table (User) in ASP.Net MVC 5 - Fluent API

荒凉一梦 提交于 2020-01-11 12:02:33
问题 I am learning ASP.Net MVC 5 and I am stuck with one basic DB Design. So, I have one User which can refer many person in job Also, many person can apply to get themselves Referred. I have created two roles and all of that is taken care. Now, I have on class called Referral which will keep track of every instance of Referral that needs to be done. Referral Model: Public class Referral { [Key] public int ReferralId { get; set; } public Company Company { get; set; } public int CompanyId { get;

How to handle many to many same table (User) in ASP.Net MVC 5 - Fluent API

流过昼夜 提交于 2020-01-11 11:59:17
问题 I am learning ASP.Net MVC 5 and I am stuck with one basic DB Design. So, I have one User which can refer many person in job Also, many person can apply to get themselves Referred. I have created two roles and all of that is taken care. Now, I have on class called Referral which will keep track of every instance of Referral that needs to be done. Referral Model: Public class Referral { [Key] public int ReferralId { get; set; } public Company Company { get; set; } public int CompanyId { get;

The HTTP verb POST used to access path '/Membership/user/' is not allowed

北慕城南 提交于 2020-01-11 11:51:34
问题 This code: private void Submit_Click(object sender, RoutedEventArgs e) { user temp = new user(); temp.Username = UserName.Text; temp.Password = Password.Text; dataBase.AddTouser(temp); IAsyncResult result = dataBase.BeginSaveChanges(new AsyncCallback (OnSaveChangesCompleted), temp); } void OnSaveChangesCompleted(IAsyncResult result) { try { string name = ((user) result.AsyncState).Username.ToString(); dataBase.EndSaveChanges(result); } catch (DataServiceRequestException ex) { MessageBox.Show(

The HTTP verb POST used to access path '/Membership/user/' is not allowed

自闭症网瘾萝莉.ら 提交于 2020-01-11 11:49:30
问题 This code: private void Submit_Click(object sender, RoutedEventArgs e) { user temp = new user(); temp.Username = UserName.Text; temp.Password = Password.Text; dataBase.AddTouser(temp); IAsyncResult result = dataBase.BeginSaveChanges(new AsyncCallback (OnSaveChangesCompleted), temp); } void OnSaveChangesCompleted(IAsyncResult result) { try { string name = ((user) result.AsyncState).Username.ToString(); dataBase.EndSaveChanges(result); } catch (DataServiceRequestException ex) { MessageBox.Show(

Performing projections on multiple databases with only one dbContext

风格不统一 提交于 2020-01-11 11:38:08
问题 We are using EF.Core for a current project. The project has three databases which is a real nuisance that can't really be avoided. The databases have the same structure. So we are able to swap contexts and use the same EF Model to do CRUD operations. We have one particularly complex query that we are going to be porting over from traditional ADO.NET raw SQL. The problem is it is a cross database query. To replicate this issue what we really need is a way to have all three tables for the query

Strange behavior of INCLUDE in Entity Framework

眉间皱痕 提交于 2020-01-11 11:17:01
问题 This works: using (var dbContext = new SmartDataContext()) { dbContext.Configuration.ProxyCreationEnabled = false; var query = dbContext.EntityMasters.OfType<Person>(); if (includeAddress) query.Include(p => p.Addresses); if (includeFiles) query.Include(p => p.FileMasters); output.Entity = query.Include(s=>s.Addresses).FirstOrDefault<Person>(e => e.EntityId == id); } while this doesn't: using (var dbContext = new SmartDataContext()) { dbContext.Configuration.ProxyCreationEnabled = false; var

Entity Framework - Conditionally adding columns into group by

北慕城南 提交于 2020-01-11 10:44:11
问题 I want to conditionally add columns into GroupBy clause but I am not sure how it can be done. I have 5 columns which I want to add in group by statement depending upon user's input. To do this I have following properties: ProductId ColorId PieceId SizeId WeightId If any property has value greater than 0 then this column needs to be used in group by clause. So if ProductId, ColorId and PieceId has value greater than 0 than following should be there in group by: list.GroupBy(p => new { p

exact sql query executed by Entity Framework

家住魔仙堡 提交于 2020-01-11 10:41:49
问题 the question seems clear enough, but I'll add a case using (var context = new MyEntities()) { if(context.mytable.Any(row => row.myfield == 2)) { // do something here } } I am new to Entity Framework. I don't know how to check the exact sql query executed? 回答1: You can find a similar question here: How to view generated SQL from Entity Framework? To sum up, your choices are: LINQPad SQL Server Profiler Entity Framework Profiler See the referenced question for details. 回答2: As the above answers

exact sql query executed by Entity Framework

你离开我真会死。 提交于 2020-01-11 10:41:17
问题 the question seems clear enough, but I'll add a case using (var context = new MyEntities()) { if(context.mytable.Any(row => row.myfield == 2)) { // do something here } } I am new to Entity Framework. I don't know how to check the exact sql query executed? 回答1: You can find a similar question here: How to view generated SQL from Entity Framework? To sum up, your choices are: LINQPad SQL Server Profiler Entity Framework Profiler See the referenced question for details. 回答2: As the above answers

Entity Framework and OFFSET/FETCH on Sql Server

自作多情 提交于 2020-01-11 10:36:29
问题 I just encountered a weird bug in my app where a paged data grid contained duplicate rows. Investigation showed that it's because the new paging mechanism Entity Framework uses with Sql Server 2012 as of version 6.1.2 only works on strictly ordered column sets , as is documented here. Since most columns are not strictly ordered (meaning you have duplicate entries with respect to the sort order), simply binding one of the typical grid middlewares to Entity Framework is now broken subtly and