entity-framework-5

Saving images to database with asp.net mvc 4 + Entity Framework

偶尔善良 提交于 2021-02-06 13:22:49
问题 I have this: Model: public string Picture { get; set; } [Column(TypeName = "image")] public byte[] Image { get; set; } [Display(Name = "Display profile Image")] public bool DisplayItem { get; set; } View: <div class="editor-label"> @Html.LabelFor(model => model.DisplayItem) </div> <div class="editor-field"> @Html.EditorFor(model => model.DisplayItem) @Html.ValidationMessageFor(model => model.DisplayItem) </div> <div class="editor-label"> @Html.LabelFor(m => m.Image) </div> <input type="file"

How do I define multiple EF DbContexts that share the same structure so they can use methods interchangeably?

落花浮王杯 提交于 2021-01-29 16:00:11
问题 I am using a single database design for 3 different SQL Server locations (production, backup, master). The design is simple, shown below for the production location: Public Class ProductionDbContext Inherits DbContext Public Sub New() MyBase.New("ProductionDbConnection") End Sub Public Sub New(connectionString As String) MyBase.New(connectionString) End Sub Public Property Tables As DbSet(Of Table) 'Table includes a List(Of Topic) Public Property Topics As DbSet(Of Topic) 'for direct access

EF inheritance and primary keys

北城以北 提交于 2021-01-28 00:18:17
问题 I'm not sure whether this is possible in EF, but I am creating a bunch of classes and am trying to get EF to create the tables for me. Now EF creates my tables fine, except for a minor issue. It created the tables as: Person - PersonId (PK) Foo - PersonId (PK) - FooId (INT) Poo - PersonId (PK) - PooId (INT) Ideally, I want the PersonId in tables Foo and Poo to be a foreign key not as the primary key. Is this possible? Tried using the ModelBuilder to do this via: modelBuilder.Entity<Foo>()

how to map composite key in CRUD functionality

|▌冷眼眸甩不掉的悲伤 提交于 2020-05-28 18:53:16
问题 I need to map based on two keys(comp and part). @foreach (var item in Model) { <tr> <td> @Html.DisplayFor(modelItem => item.comp) </td> <td> @Html.DisplayFor(modelItem => item.part) </td> ........................... <td> @Html.ActionLink("Edit", "Edit", new { id=item.comp }) | @Html.ActionLink("Details", "Details", new { id = item.comp }) | @Html.ActionLink("Delete", "Delete", new { id = item.comp }) </td> </tr> } how to use composite key in Index page and also in controller. public

how to map composite key in CRUD functionality

五迷三道 提交于 2020-05-28 18:39:13
问题 I need to map based on two keys(comp and part). @foreach (var item in Model) { <tr> <td> @Html.DisplayFor(modelItem => item.comp) </td> <td> @Html.DisplayFor(modelItem => item.part) </td> ........................... <td> @Html.ActionLink("Edit", "Edit", new { id=item.comp }) | @Html.ActionLink("Details", "Details", new { id = item.comp }) | @Html.ActionLink("Delete", "Delete", new { id = item.comp }) </td> </tr> } how to use composite key in Index page and also in controller. public

Entity Framework 5 - code first array navigation property one to many with Interface Type

寵の児 提交于 2020-05-13 08:03:11
问题 These are my classes: public class Post : IPost { public int Id { get; set; } public virtual int[] DuplicateOf { get; set; } public virtual ICommentInfo[] Comments { get; set; } } public class CommentInfo : ICommentInfo { public virtual string Author { get; set; } public virtual int Id { get; set; } public virtual string Text { get; set; } public virtual int PostId{ get; set; } [ForeignKey("PostId")] public virtual Post Post { get; set; } } With this CommentConfiguration added to