entity-framework

How does one Attach to an MDF file created by Code First using Server Explorer

青春壹個敷衍的年華 提交于 2020-01-06 13:56:11
问题 Given: Code First Technique (all properly done and validated). I can actually, in the application see records added from the program. This means all the SaveChanges and subsequent queries are working. Problem: I want to expose this DB to another program but cannot get Server Explorer Data Connections to attach to it... What did you try? In VS2013 I opened the Server Explorer, clicked on Add Connetion and entered this (after changing the DataSource to SQLClient and not the default database

Passing string into a Constructor of DbContext with a Base class is not setting the value

别来无恙 提交于 2020-01-06 13:29:57
问题 I have decide out of a business need to make a change to my DbContext class Previously my code looked like this: public class RPMContext : DbContext { public RPMContext() : base(ConnectionString()) { } private static string ConnectionString(string connection) { conn = ConfigurationManager.ConnectionStrings["LH_RPMContext"].ConnectionString; return conn; } } Above "Works" but I need to be able to PASS in a string in which I'm able to set the static method ConnectionString to OTHER specified

Passing string into a Constructor of DbContext with a Base class is not setting the value

大城市里の小女人 提交于 2020-01-06 13:29:37
问题 I have decide out of a business need to make a change to my DbContext class Previously my code looked like this: public class RPMContext : DbContext { public RPMContext() : base(ConnectionString()) { } private static string ConnectionString(string connection) { conn = ConfigurationManager.ConnectionStrings["LH_RPMContext"].ConnectionString; return conn; } } Above "Works" but I need to be able to PASS in a string in which I'm able to set the static method ConnectionString to OTHER specified

EF7 nested Include not showing in Razor .net

大兔子大兔子 提交于 2020-01-06 13:11:34
问题 I have my models like this: Goup.cs GroupUser (pivot table) ApplicationUser (User) -> 4. Profile And now I want to show the data in Profile on a details page when the User belongs to the group. I'm doing this like this: private IEnumerable<GroupUser> GetUsers(int groupId) { IEnumerable<GroupUser> model = null; if(groupId == 0) { model = _kletsContext.GroupUser.OrderByDescending(o => o.GroupId).AsEnumerable(); } else { model = _kletsContext.GroupUser.Where(g => g.GroupId == groupId).Include(p

EF7 nested Include not showing in Razor .net

不羁岁月 提交于 2020-01-06 13:10:43
问题 I have my models like this: Goup.cs GroupUser (pivot table) ApplicationUser (User) -> 4. Profile And now I want to show the data in Profile on a details page when the User belongs to the group. I'm doing this like this: private IEnumerable<GroupUser> GetUsers(int groupId) { IEnumerable<GroupUser> model = null; if(groupId == 0) { model = _kletsContext.GroupUser.OrderByDescending(o => o.GroupId).AsEnumerable(); } else { model = _kletsContext.GroupUser.Where(g => g.GroupId == groupId).Include(p

What are the pros and cons of having a WebAPI in the same or different project [closed]

孤街醉人 提交于 2020-01-06 13:09:33
问题 Closed . This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed 4 years ago . I have an MVC application and the solution consist of three project as described below: Store.Domain : Holds the domain entities and logic (repositories created with the Entity Framework). Store.WebUI : Holds the controllers and views; acts as the UI for the application.

Grid only updating when main gridwindow is closed

眉间皱痕 提交于 2020-01-06 12:52:46
问题 I have to forms one containing a grid view then a popup that the user can edit the values of the gridview its saving the data ok but only when i close the main gridview window But the data does not get refershed in the blow grid until i close the main form I am calling the form from the double click of the grid Dim invId As Object = dgDeliverys.Rows(e.RowIndex).Cells("r3DeliveryId").Value Dim frmedit As New frmedit(invId) frmedit.ShowDialog() BindGrid() Then in the new constructor i am usig

C# ASP.Net MVC dynamic object properties

我的未来我决定 提交于 2020-01-06 11:46:08
问题 I am working on a ASP.NET MVC project, with C# , and EF code first. I am required to add dynamic properties to entities. For example - I have a car as a base object. I can add custom properties for it like engine power, length, color etc etc. Properties can be boolean, int, string or select options (ie, i have to create checkbox, input or select html elements when a user inputs values for those properties). Properties must have custom validation rules (i.e., required, number only, range only

MVC ModelState IsValid reports true when should be false

你说的曾经没有我的故事 提交于 2020-01-06 10:56:32
问题 I have the following 3 classes (all code now included)... using System.ComponentModel.DataAnnotations; namespace MyWebApp.Models { public class ApplicationUser { [Display(Prompt = "Your Name", Name = "Contact Name"), Required(), StringLength(255, MinimumLength = 3, ErrorMessage = "Please enter a valid contact")] public string ContactName { get; set; } [Display(Name = "Username", Prompt = "Login As"), Required(), StringLength(255, MinimumLength = 3, ErrorMessage = "Your username must be at

MVC ModelState IsValid reports true when should be false

烈酒焚心 提交于 2020-01-06 10:56:11
问题 I have the following 3 classes (all code now included)... using System.ComponentModel.DataAnnotations; namespace MyWebApp.Models { public class ApplicationUser { [Display(Prompt = "Your Name", Name = "Contact Name"), Required(), StringLength(255, MinimumLength = 3, ErrorMessage = "Please enter a valid contact")] public string ContactName { get; set; } [Display(Name = "Username", Prompt = "Login As"), Required(), StringLength(255, MinimumLength = 3, ErrorMessage = "Your username must be at