The ADO.NET Entity Framework is a set of ORM (Object-Relational-Mapping) tools for the .NET Framework, since version 3.5 SP1.
5
votes
1answer
95 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
53 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 | ...
1
vote
1answer
103 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
94 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
143 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
54 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
232 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
...
1
vote
1answer
123 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
63 views
Repository pattern and unit of work
I implement 2 distinct class from an repository interface
public interface IRepository<T>
{
bool TryGet(Func<T, bool> predicate, out T entity);
T Get(Func<T, bool> ...
0
votes
0answers
36 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
106 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
109 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
155 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 ...
4
votes
1answer
679 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
1answer
138 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
77 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
103 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
45 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 ...
1
vote
1answer
1k 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
110 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>
{
...
3
votes
0answers
925 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 ...
1
vote
1answer
115 views
Passing an entity to use it's fields to update method is ok to do?
I have two different ideas on how to handle this Update method in my MVC Model class "DataAccess" And I'm wondering if in the first, I'm handling my class incorrectly or ambiguously, because I'm using ...
0
votes
1answer
114 views
Products table or Products + attributes when using EF + MVC 4 [closed]
What I need to build is a web application that maintains and shows products. A product has a lot of attributes, some that will be changed or added during the next year. I have 2 options for designing ...
4
votes
4answers
401 views
Is this bad code? (Instantiating if null)
I often have static classes which uses the DataContext somehow, and they all make a new DataContext, but often i allready have one instantiated elsewhere, so why not use that?. And then i would do ...
2
votes
0answers
57 views
Does my design follow the single responsibility principle
I'm working on a site that has to do with movies. I am consuming the Rotten Tomatoes API to get my movie information and using EF5 with a code first approach to get that into the database. I'm using ...
8
votes
2answers
15k views
Entity Framework Generic Repository Pattern
Thought 1
public interface IRepository<T> : IDisposable where T : class
{
IQueryable<T> Fetch();
IEnumerable<T> GetAll();
...
4
votes
2answers
389 views
Trying to clearly seperate my logic in my program
My problem is I need to know
is my code in my CRUD functions structured well and effectively? I plan to implement CRUD for Locations entity too. hopefully without redundant code.
you see how one ...
0
votes
1answer
156 views
Making a Custom class less specialized but just as understandable?
In my C# program, I have a class defined as follows:
public class DbResult
{
public bool bSuccess { get; private set; }
public String Message { get; private set; }
private DbResult(bool ...
1
vote
1answer
229 views
Am I using too many functions in my DataAccess Class?
I am wondering if in particular the function called AssignDBStatusMessage and TryDataBaseAction are unnecessary. It seems to me that the logic is more cluttered if i do away with those functions. ...
6
votes
1answer
971 views
ListBox for a many to many relationship
I'm looking for a good and easy to use solution for creating MultiSelectLists in MVC for many to many relationships.
I have this following example code and it works fine, but it just takes a lot of ...
1
vote
2answers
248 views
How to organize this code and prepare more versatile CRUD functions?
I am using C# and the .net entity framework, and I'm also learning how to better use OOP concepts in my program. My code is all displayed below. I would like to ensure my logic is properly organized ...
0
votes
2answers
274 views
using 2D array to read datatable ok? or repeatedly call function that reads record by record?
I am asking this for coding style. I have a program class that calls a function(of a data access class) that reads from a table (using entity framework by the way), and I'm preparing to write the ...
6
votes
1answer
292 views
combining 4 CRUD functions into 1?
I have a console application that I'm trying to make with minimal redundant code.
I have 4 functions, Create, Read, Update, and Delete.
is it possible or practical to combine the four functions ...
5
votes
2answers
199 views
How to reduce my code length without changing concept?
There are three servers. I want to assign a job to a server which has least NotStarted jobs. I have achieved this, but my code is very lengthy. I don't know how to minimize my code without changing my ...
4
votes
0answers
331 views
Multiple repository calls or LINQ query
These two methods do the exact same thing (or at least they are supposed to!). They both pass a simple test based on a mock context. Neither has been exposed to any integrated testing yet.
Would ...
4
votes
2answers
815 views
Threadsafe DBContext in singleton
I found out the hardway that access to DbContext in .NET is not threadsafe. I have a singleton for logging things using a dbcontext. The original version uses something like
public Logger{
private ...
8
votes
2answers
4k views
Generic repository and unit of work code
I am writing a WPF application that needs to access information from a database (I am currently using Entity Framework code first, so data access is via DbContext).
My ViewModels directly ...
0
votes
1answer
185 views
Is it proper TPT Inheritance
I have following model and database created using Entity Framework. Is it proper TPT Inheritance?
Is it possible to make the base class as abstract?
Model
Database
CODE
namespace LijosEF
{
...
1
vote
2answers
543 views
Many to many crud using entity framework 4.1
My view submits data to the controller using Json objects which contains child objects.It allows users to add/remove/modify the relationship with child entities(authors,categories,LIbraryBookCopy). ...
2
votes
0answers
418 views
Linq-to-entities query too slow
I am fairly new to Entity Framework and I am not sure I am really using it to it's max potential. I have this query, that IMHO seems to take a little longer than I feel it should. I have tried ...
2
votes
1answer
1k views
Your Thoughts: Entity Framework Data Context via a DataHelper class (centralized context and transactions)
I want to get opinions on the code I have put together for a centralized DataContext via a DataHelper class that I have created to be re-used on projects.
NOTE - there is a ton of code here, sorry ...
2
votes
1answer
676 views
IAuditable and IArchivable Repository with Repository Pattern and UnitOfWork
I am quite new to ASP.net and am currently trying to implement my data access layers of my application. I have so far implemented a generic repository pattern as follows:
using System;
using ...
1
vote
1answer
155 views
How could I remove repetition from this linq-to-entities query?
This linq query works, and it does what I want it to do, but is there any other way I could improve the query so I'm not repeating a.AnswerRevisions.OrderByDescending(r => ...
5
votes
1answer
209 views
LINQ Compare Query Improvements?
I'm attempting to create a compare table to compare products depending on the add-ons they have. To grab the data and filter it I'm using LINQ To SQL.
Table's Layout (Cut short):
Products Table
ID
...
1
vote
0answers
138 views
Is my MergeUtility good enough to create an open source project out of?
Here is a utility that supports ETL/merging in EntityFramework.
If it's not appealing as a general purpose tool, why?
If it is appealing as a general purpose tool, how might the design be made ...
2
votes
1answer
246 views
Clever way to build a extension method that ordenate my IQueryable<T>?
I want to create a ExtensionMethod to ordenate my linq query, called Ordenar. I'll sort it depending what columns is in sortColumns ListDictionary.
I tried some ways, but the best way I arquieve was ...
2
votes
2answers
160 views
Can someone tell me if I'm barking up the wrong tree with this ASP.Net MVC/Entity Framework pattern?
So I have experience is C#/ASP.Net, and I've done MVC in Ruby On Rails, so I figured making the jump to ASP.Net MVC would be a breeze. Unfortunately, I'm second guessing my every descision. I'd like ...
3
votes
0answers
492 views
Efficient way to deal with maintaining Many:Many relationships in EF Code-First, ASP.NET MVC
(I posed this in SO, but since it's a kind of code-review question, it's now here too)
I've got this all working, but it seems to be quite long winded, and I thought I'd post here and see if I'm ...
3
votes
1answer
373 views
LINQ generating chart
I'm generating a table to use on jQuery visualize plugin and generate a chart. The code is pretty good, but maybe there is a way to improve it. Maybe do more work on the LINQ query and less stuff on ...
3
votes
2answers
150 views
Could generics condense these two methods into one?
Two methods which do very similiar things, is it possible to condense these somehow? This is using the Entity Framework.
public void ExportSiteData (FLEX_INV_EXP_SITE siteData)
...