I want to perform a generic insert in entity framework. This is what I wrote -
static public void Insert<T>(MyEntities DataContext, T obj) where T : class
{
try
{
DataContext.AddObject(DataContext,obj);
DataContext.SaveChanges();
}
catch (Exception e...
Hello, I have started to look at the Entity Framework for a project I am doing and going down the road of using a BLL against it via the the repository pattern. As I understand it for each entity I should create a repository for it so I would have
public class UserRepository : IRepository<User>
{ ... }
and
public class AccountReposi...
I'm trying to serialize an entity and all its related entities for storing as xml before physically deleting the entity (leaving an audit trail).
I'm using a DataContractSerializer which seems to be getting around the shallow serialization performed when using an XmlSerializer.
The only trouble is that only related entities that have b...
How can I use cast in Linq to Entities?
I need something like this:
if (typeof(myObject) is IMyInterface)
{
return MyObjectSet.Where(x => ((IMyInterface)x).MyProperty == 1);
}
If I try above code, I get an exception. It's an expected behavior of EF or it's a bug?
...
I'd like to know if it is possible to map some database columns to a custom data type (a custom class) instead of the basic data types like string, int, and so on. I'll try to explain it better with a concrete example:
Lets say I have a table where one column contains (text) data in a special format (e.g a number followed by a separator...
How can I undo changes when a SaveChanges() doesn't succeed ?
contextObject.Toto.AddObject( new Toto());
try
{
contextObject.SaveChanges();
}
catch
{
// Undo changes !
}
In this sample, I'd like to remove the new Toto object in memory. I don't want to remove it manually. I'd like to synchronize my contextObject to my databa...
(This looks like a long question, but it's not really, honest!)
I am trying to get a simple proof of concept working with Entity Framework 4 and the CTP 3 version of Code Only. It feels like I'm missing something really obvious and simple.
I have this following test which is failing:
[TestFixture]
public class ParentChildTests
{
[...
I always use a try catch when i am dealing with database related operations for eg.
try
{
DataContext.AddtoObjectname(obj);
DataContext.SaveChanges();
}
catch(Exception e)
{
throw new Exception("Problems adding object" + e);
}
But I read about try/catch affecting performance here -
http://stackoverflow.com/questions/1308432/do-try...
Hi,
Can you please tell me some tutorials/books about thinking a large application in c#.
I have worked with 3 tier, but i need something more specific:
a way to design panels, so that for specific users specific panels will load and specific dlls
a database management so that when a user modifies an entry, others can not modify that e...
I have a table of Persons and a table of Things, where each Thing is owned by a Person and each Person has a FavoriteThing.
Persons
PersonID int <PK>
FavoriteThingID int <FK>
Things
ThingID int <PK>
PersonID int <FK>
I would like to be able to add a Person and his/her favorite Thing, as well as setting that Thing's Person...
I'm using dynamic query builder methods so I can order by dynamic columns (among other reasons).
I'm joining tables (via calls to Include) where there exists a primary-foreign key relationship. The relationship is actually one-to-one, but EF considers it one-to-many (and that can't even be manually changed directly in the navigation ...
I found the MSDN quickstart guide, but it's a bit lacking in explanation and other useful things.
Do you know where I can find a good tutorial for someone somewhat familiar with Linq-to-SQL but interested in EF?
...
I'm working on a project where most of the times I'm going to call database with a stored procedure and I'm a little bit confused what should I do. Options are not just restricted to Sql to Linq and EF. If there are any better options please suggest them too.
UPDATE - Reason for using SPs
I've to apply logic in many of the stored proced...
hi,
i'm learning EF4 and would like someone to recommend the best practice on how to search for entities using complex criteria in a stored procedure and return entities and their navigation properties.
So lets say i have a table for Customer and a table for Contact. A customer can have many contacts. The customer table contains the Cu...
I try to use the new POCO capabilities of EF 4.0 in combination with the EFOracleProvider. I have recompiled the EFOracleProvider (using ODAC instead of System.Data.OracleClient) to target the .NET Framework 4 (und put it in the 4.0 GAC). Everything ok so far.
I host the Entity Model in a WCF Data Service:
class DivaDispoDataService : ...
In a previous post there was mentioned using an overload of the Select method to reference an Index value. This would be exactly what I need to answer this question
However, when I try to use this overload as below, I get a NotSupportedException
DbObjects.OrderBy (o => o.CreatedOn ).Select((o,i) => new {entity = o, rownumber = i})
I...
I have one specific view created in my DB(joins about 5-6 tables with a left join).This view is added to my edmx (entity framework 1.0) . Recently I noticed that one of the column records obtained using the edmx (linq to entities and then ToList()) got duplicated multiple times though in the database view they were different
Column-N (E...
So, In my old Linq-To-SQL I would write code like this
var tableItem = new Table
{
Prop1 = var1
Prop2 = var2,
Prop3 = var3,
ParentTableID = parentRecordID
};
db.Table.InsertOnSubmit(tableItem);
db.SubmitChanges();
After converting my working code from Linq-To-SQL to Entity Framework (v3.5) the ParentTableID property i...
I have read plenty of blog posts and have yet to find a clear and simple example of how to perform a LEFT OUTER JOIN between two tables. The Wikipedia article on joins Join (SQL) provides this simple model:
CREATE TABLE `employee` (
`LastName` varchar(25),
`DepartmentID` int(4),
UNIQUE KEY `LastName` (`LastName`)
);
CREATE TABLE `depa...
Hi I found problem with EF.
Here is my Model
I loaded asset:
POCO.Asset asset = _context.Assets.Where(a => a.UID == assetUid).First();
then I go through all properties
foreach (POCO.Property p in asset.Properties) /* request to db */ { /*...*/ }
categories:
foreach (POCO.Category p in > asset.Categories) /* request to db */ { /*...