The ADO.NET Entity Framework is a set of ORM (Object-Relational-Mapping) tools for the .NET Framework, since version 3.5 SP1.
1
vote
0answers
65 views
Entity Framework 6.0.2 - Performance of Auditable Change Tracking Part 2 of 2
This is Part 2 of a question about performance and general best practices. Part 1 is located here. The body of the messages are the same to illustrate their similarity, the difference is the code ...
3
votes
1answer
106 views
Entity Framework 6.0.2 - Performance of Auditable Change Tracking Part 1 of 2
This is Part 1 of a question about performance and general best practices. Part 2 is located here. The body of the messages are the same to illustrate their similarity, the difference is the code ...
5
votes
1answer
54 views
A generic way to use LINQ to Entity with types and operations unknown until run time
A question was asked here about reflection and LINQ to entity. I'm trying to modify the code that was presented to fit my needs, but it appears both Smeegs and Servy are quite a bit smarter than I am ...
7
votes
3answers
141 views
'Better' way to handle adding a record
Scenario: I am using a helper class called 'OutputHelper' to add a new record to the table 'Output'. My 'Output' object contains the following:
ShiftID
Model
WorksOrder
LotNo
Quantity
ShiftHour
I ...
1
vote
0answers
72 views
Code First/Database First Entity Framework MVC [closed]
The following example is taken from the book Pro ASP.NET MVC 4 - Adam Freeman. This book does a good job going over the basics of the MVC framework. In it a database is created from a Product class ...
4
votes
1answer
117 views
Code First Entity Framework
Is the following good design for doing entity framework code first? What am I missing for a production system? I haven't included all my code, just a snapshot...
EDIT: My application, doesn't update ...
1
vote
1answer
57 views
A genric extension method to filter Linq-EF queries
I have various types of EF entities, all of them have a navigation property called "Employee". When generating reports the user will have the option to filter the report according to the different ...
8
votes
2answers
142 views
Should a year and month be stored as separate fields or as a date?
We have a table with calculated data that groups sales by product, year and month, to provide fast querying for statistics.
My colleague argues that the year and month should be two separate fields, ...
0
votes
0answers
43 views
Can this DbGeography calculation be done better?
Given the following piece of code, can it be done better:
public object DistanceFrom(
IEnumerable<Coordinate> coordinates) {
IEnumerable<DbGeography> addresses = ...
4
votes
1answer
199 views
Entity Framework, code-first repository pattern review. Where to validate?
I've been iterating on my repository pattern implementation over the course of the past 4-5 months. In my new projects I choose to use this pattern and I try to improve upon what I learned in previous ...
5
votes
1answer
91 views
Logging Entity Framework Changes - improve performance
I have the following code to log changes using Entity Framework 6.
At the moment it only logs changes to a particular table - but I intend to expand it to cope with any table. I'm not sure of the ...
1
vote
1answer
45 views
Inserting using multiple contexts into LocalDB
I've written this ActionResult to model an Order that goes through. I couldn't think of another way to write this without using context Db<Sets>. It runs kinda slow, taking around 4 seconds to ...
1
vote
1answer
81 views
Unit of work and common implementation
I have some questions regarding a common implementation of the UoW, Repository Pattern and EF:
public interface IAppUow
{
void Commit();
IRepository<Customer> Customer{ get; } // ...
3
votes
1answer
54 views
Retrieving statistics about URL clicks
I'm pretty new to ASP/MVC but have had some prior programming experience.
I am trying to retrieve statistics about URL clicks - total clicks and unique clicks by IP address. I started with:
...
1
vote
1answer
57 views
EF adding Item with children
I'm working on my pet project with MVC 5 and EF, and everytime I'm adding a parent with it children (I have the children ID's) I have to go to the database, because if I just create a new child with ...
5
votes
2answers
557 views
Update only modified fields in Entity Framework
I'm working on a website on ASP.NET MVC4 and EF5. I want to ensure that only modified values are updated in the database. I'm using a unit of work pattern and repositories for data work. Here's the ...
2
votes
1answer
189 views
Is this correct usage of Repository + Unit of Work + Service Pattern
I have project where I need to use C# and Entity Framework.
After my question here, I have decided to use Unit of Work and Repository patterns.
This is the first time when I'm using this. Can ...
2
votes
1answer
134 views
Nested select Linq
Is there a simpler and optimized way to calculate listAdminCorePriveleges and privileges ?
public string[] GetPrivilegesForUserByPersonEntityId(int personEntityId)
{
var listPrivileges = ...
1
vote
1answer
57 views
Metadata query performance optimization
SQL Server 2008 R2 + .NET 4.5:
I have the following metadata table:
CREATE TABLE [dbo].[Metadata](
[Id] [uniqueidentifier] NOT NULL,
[ContentId] [uniqueidentifier] NOT NULL,
...
2
votes
1answer
195 views
Enabling discard pending changes on DbContext
This code review request is tightly coupled with this SO question, this is the solution I implemented to solve the problem being asked about there.
All my ViewModels get constructor-injected with a ...
5
votes
1answer
2k views
Entity Framework using Repository Pattern, Unit of Work and Unity - viable approach?
Using a combination provided from this example and this implementation, I'm creating a solution that decouples the UnitOfWork class from the individual repositories, as they violate the Open-Closed ...
2
votes
1answer
2k views
Unit of Work and Repository Design Pattern Implementation
User and Role are just examples; also, code is sparse on purpose (i.e. for demonstration purposes only).
Thoughts? (e.g. good, bad, etc.)
Interfaces
public interface IEntity
{
int Id { get; }
}
...
1
vote
1answer
93 views
Creating models manually in mvc
I am creating my models manually.
I have five tables in my database as follows :
1. Members
2. MemberTypeMasters
3. Payments
4. Relationships
5. StatusMasters
My Database looks like :
So far I ...
0
votes
1answer
153 views
Serialize the properties of an entity framework entity to data fields and back
I am trying to write code to convert properties of an Entity Framework entity to strings and back.
Here is the code so far that converts back from strings to the object properties.
I am stuck trying ...
1
vote
0answers
68 views
Review WCF client class
Please review, the class is responsible for wrapping requests to a WCF Data Service, which tidies up calling code. Transactions are implicitly supported. It should efficiently send just updates to the ...
2
votes
1answer
541 views
When to use separate DBContext classes?
I know that the DBContext represents a session (Unit-Of-Work and Repository) with the database, however I an unsure as to when I should have a different DBContext. Currently, I have a separate ...
4
votes
2answers
568 views
MVC Layered Project Structure
We are starting a new web project using C# / MVC 4 and Entity Framework 5 for data access. I've decided to go with an n-layered approach for the structure of the project and I would like some feedback ...
4
votes
1answer
278 views
DbSet<T> IncludeAll method
The Problem
As an ASP.NET MVC4 developper, I'm using Entity Framework a lot. Considering performance I often use lazy loading for my models.
public class Result {
public int Id { get; set; }
...
2
votes
3answers
73 views
Best Practice - Passing by Entity or EntityId in repositories?
Which is the best practice in getting data from repository? passing just by object or by Id?
public IQueryable<Attendance> GetByPersonId(int id)
{
return DbSet.Where(ps => ...
5
votes
1answer
130 views
Can this ordering logic be done better?
I am creating an ASP.NET MVC 4 app using Entity Framework and currently I am creating orderable tables. For that I have created the following logic to handle the different orders:
if (orderKey == ...
-1
votes
2answers
130 views
How does this GetType() work? [closed]
I thought .GetType() was a method that had to be used like myProperty.GetType(). But, as you can see, it is being used simply by itself:
(from p in GetType().GetProperties(BindingFlags.Instance | ...
3
votes
1answer
439 views
Review Repository and UnitOfWork implementation
I've done a LOT of reading about creating a Unit Of Work and Repository based implementation for my Entity Framework based application. I have come up with the following - what problems can you find?
...
2
votes
1answer
111 views
How can I make this code better
I hate having almost two identical blocks do almost the exact same thing.
I am working with Entity Framework 4.4.0.0
Asp.Net MVC
Right now if the user is a "manager" I want to show them the entire ...
1
vote
1answer
552 views
Updating entities with EF (Delete, Add, Update) with one method
I have a WCF service, which has a method for updating a EF entity. The update method works just fine but looks ugly. I think due to some EF design I have to manually set the change tracker state to ...
1
vote
1answer
209 views
Making a property virtual to cause EF to load the property?
I am walking through a sample MVC4 ASP.Net tutorial available on PluralSight.com, by Scott Allen. I am in a section #5, Working with Data (part 2), "Listing Reviews".
This application has a database ...
2
votes
3answers
3k views
Using Linq to select the first and last values
I want to get just the first and last values in a date range. I have the following code:
using (var myEntities = new dataEntities())
{
var myValues = (from values in myEntities.PointValues
...
2
votes
1answer
242 views
Feedback and Advice on my N-Tier Application Architecture
I am working on an application that will use an N-Tiered approach. I would appreciate any feedback and advice on my architecture before I proceed any further.
DataLayer (Class Library Project)
...
2
votes
0answers
111 views
Repository pattern and unit of work [closed]
I implemented 2 distinct classes from a generic IRepository interface:
public interface IRepository<T>
{
bool TryGet(Func<T, bool> predicate, out T entity);
T Get(Func<T, ...
2
votes
1answer
100 views
Abstract repository for entity framwork
I write abstract repository
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Linq.Expressions;
namespace ...
3
votes
2answers
114 views
Refactoring from .. in .. select to more compact one
Is it possible to write the two following lines of code in a more compact one?
IEnumerable<int> collection = from partnerNumbers in contract.Contact.PartnerNumbers select partnerNumbers.Pnr;
...
1
vote
2answers
117 views
How to optimize/refactor this method?
Here is my method:
public JsonResult ValidateAll(string toys)
{
Dictionary<string, object> res = new Dictionary<string, object>();
List<string> result_check = new ...
1
vote
1answer
231 views
How can I implement the generic repository pattern and improve the performance for the code below?
I've used EF-DB first approach and have written a simple app to retrieve the data from the database and show it in the view. The code is simple and ok for a beginner like me, but how can I implement ...
5
votes
1answer
3k views
Looping through columns in Entity Framework
Is there a cleaner/more efficient way to loop through the columns in EF implicitly than the way written below?
static void Main(string[] args) {
using (var db = new someDbContext()) {
var ...
3
votes
2answers
471 views
Code-First TPT, TPC, or incorrect inheritance?
My question is: based on the business need below, should I use Table-Per-Type, Table-Per-Class/Concrete-Type, or am I misusing inheritance in the first place? If TPT, will the query performance ...
2
votes
2answers
79 views
Optimizing a distinction code
List<int> types = new List<int>();
foreach (var d in myTableList)
{
if (!types.Contains((int)d.item_type))
types.Add((int)d.item_type);
}
I have a table in db called myTable. ...
3
votes
1answer
137 views
Optimization of code for searching in db
This is my code:
var test = (from x in myDb.myTable
where (x.name == tmp || x.name == tmp2 || x.name == tmp3) && x.unit == u
select x).FirstOrDefault();
if (test == ...
1
vote
0answers
71 views
AlwaysUpdate attribute for Entity Framework Code First POCO
The entity framework will only save properties it detects has changed via its proxy classes. I have a situation where I want a property to always be saved no matter if it changed or not.
I wrote a ...
2
votes
1answer
4k views
Entity Framework & Unit Of Work Design issue with Repository & DI, Please Help
I am facing a problem to save data using UnitOfWork. I mean I am unable to save data using UnitOFWork.Commit() from Controller class. My Implementation check bellow.
IUnitOfWork
public interface ...
1
vote
2answers
139 views
Is my code (clean code separation) is correct?
The code below is an approach of clean code separation, but I am confused if it is a right approach or wrong. Please suggest me.
public interface IRepository<T>
{
...
6
votes
1answer
3k views
Correct usage of EF's DBContext in ASP.NET MVC application with Castle Windsor
I am trying to use Entity Framework as simple as posible. Use UnitOfWork and Repository patterns seems to be overkill because whole web application will be pretty straightforward. I came with this ...