Posts

Showing posts with the label entity-framework

Query string properties stored as XML

Query string properties stored as XML I am using Entity Framework to query a db which is defined by a model: inside this model I have several classes having a #region dynamic values : #region dynamic values [DataContract] public class Job : AbstractEntity, IJob { [DataMember] public virtual Guid Id { get; set; } ... #region dynamic values [DataMember] public virtual string MetadataValue { get; set; } [DataMember] public virtual string ParametersValue { get; set; } [DataMember] public virtual string AttributesValue { get; set; } #endregion #region links ... #endregion } AttributesValue , MetadataValue and ParametersValue are declared as string but are stored inside the db as XML documents. I am aware that this is not consistent with the model and should be changed, but for some reasons it has been managed this way and I am not allowed to modify it. I have created a Unit Test in order to better handle the problem, and here is the ...

query from multi table show in tableview

query from multi table show in tableview I Have 16 tables with difference columns and some common data. And I wanna to show these Common data in one Table in view. Now I use Entity Framework to query from these 16 tables and Use 16 Foreach to put theme in a Common List<Common_ViewModel> and after all send this List to my view : return view(List); List<Common_ViewModel> But My database is big and process take more time. what is the best Idea with multi table query and show common data of tables in one table in View ? Have you tried to create a view, with joins, then update your edmx to mapp the view and the use it, or use stored procedure – Mohammad Ali Jul 1 at 9:22 If you are using a SQL Sever it is probably quicker to use a stored procedure to create the view. – jdweng ...

Entity Framework : getting an object inside my class from the drop-down list id

Entity Framework : getting an object inside my class from the drop-down list id I want to create an object from the class Expediente : Expediente public class Expediente { //Para que sea key y no genere identity la BD [Key] public int Codigo { get; set; } [Required] public Tramite Tramite { get; set; } //no le pongo requiered para que no de error al crearlo sin esto public DateTime FechaCreacion { get; set; } //por defecto hay que ponerlo en true public Boolean abierto { get; set; } [Required] public Funcionario Funcionario { get; set; } [Required] public Solicitante Solicitante { get; set; } public virtual ICollection<EtapaCumplida> etapasCumplidas { get; set; } } I can get the Tramite and Solicitante from dropdown list without problem, but the Funcionario has another object inside of it ( Grupo ), and I don't know how to get it from the database, just from the key from Funcionario : Tramite Solicitante Funcionario G...

How to include navigation property without direct access to foreign key ID using Entity Framework?

How to include navigation property without direct access to foreign key ID using Entity Framework? I have two tables set up as one-to-many with the "one" model being Artist : Artist public class Artist { public Artist() { this.Albums = new HashSet<Album>(); } public int ArtistID { get; set; } public string UserID { get; set; } [Display(Name = "Artist name")] public string ArtistName { get; set; } public virtual ICollection<Album> Albums { get; set; } } and the "many" being Album : Album public class Album { public int AlbumID { get; set; } public int ArtistID { get; set; } public string StringExt { get; set; } public virtual Artist Artist { get; set; } } Now on an album page load, my url uses an id of type string called ID (for example https://website.com/to/albumName) to load the album page. Here's the controller: ID // GET: To public ActionResult Inde...

Entity Framework & ASP.NET MVC: can't get to the [HttpPost] on my controller from another one

Entity Framework & ASP.NET MVC: can't get to the [HttpPost] on my controller from another one I'm trying to redirect the user from this view on the SolicitantesController to the one on the Create of ExpedientesController : SolicitantesController Create ExpedientesController @model Entrega02Programacion03.Models.Solicitante @{ ViewBag.Title = "InformeSolicitante"; } <h2>InformeSolicitante</h2> <div> <h4>Solicitante</h4> <hr /> <dl class="dl-horizontal"> <dd>Cedula: @ViewBag.Cedula </dd> <dd> Nombre: @ViewBag.Nombre</dd> <dd>Apellido: @ViewBag.Apellido</dd> <dd>Email: @ViewBag.Email</dd> <dd>Tel: @ViewBag.tel</dd> </dl> <div class="form-group"> <div class="col-md-offset-2 col-md-10"> <input type="submit" value="Crear Exp...

Returning multiple records using first/earliest date

Returning multiple records using first/earliest date This is a simple concept but the LINQ/SQL solution has me stumped! In the example data below, for each ID I need to retrieve one ISRC , taking the earliest dated one for each. ISRC The data is sorted by ID/ReleaseDate/ISRC , so I could read the first/top record for each ID. ie ID 1 = GBMNA1600001 , ID 2 = GBMNA1600002 , ID 3 = GBMNA1600003 , ID 20 = GBMNA1680058 ... ID/ReleaseDate/ISRC ID ProductID ISRC ReleaseDate 1 16 GBMNA1600001 2016-03-27 00:00:00.0000000 1 26 GBMNA1680038 2016-04-24 00:00:00.0000000 1 32 GBMNA1680057 2016-05-01 00:00:00.0000000 1 132 GBMNA1680482 2016-11-13 00:00:00.0000000 1 223 GBMNA1781107 2017-03-26 00:00:00.0000000 2 5 GBMNA1600002 2016-02-14 00:00:00.0000000 2 32 GBMNA1680049 2016-05-01 00:00:00.0000000 3 13 GBMNA1600003 2016-03-13 00:00:00.0000000 3 38 GBMNA1680095 2016-05-29 00:00:00.0000000 3 485 GBMNA1880099 2018-06-26 00:00:00.0000000 20...