Menu
  • HOME
  • TAGS

How do you handle application that displays only views with EF4 plus Repository Pattern?

sql-server-2008,asp.net-mvc-4,views,entity-framework-4.1

Typically, in implementing a repository pattern you would do something like: public class ReadOnlyRepository<TEntity> : IReadOnlyRepository where TEntity : class { // Read-only methods here } public class Repository<TEntity> : ReadOnlyRepository<TEntity>, IRepository where TEntity : class { // Write methods here } You could then inject ReadOnlyRepository<SomeReadOnlyEntity> where you want...

Is it possible to add two table's data in Seed method in Entity Framework(Code-first)?

entity-framework,entity-framework-4,entity-framework-5,entity,entity-framework-4.1

this is how i solved it.... public class ContextSeeder : DropCreateDatabaseIfModelChanges<Context> { protected override void Seed(Context context) { Examination e1 = new Examination() { Description = "Science", CutOffMark = 10, QuestionID = new List<Question>() { new Question() { QuestionDes = "What is a data bus?", Answer1 = "It carries a...

Violation of PRIMARY KEY constraint. Cannot insert duplicate key

c#,sql,asp.net-mvc-3,entity-framework,entity-framework-4.1

The duplicate key value is (0) I'm guessing that your table is not set to automatically populate your primary key value as an identity property. The declaration should look something like this: ClearinghousePartners int primary key PK_ClearinghousePartners identity ...

Conditionally save secondary table objects

c#,asp.net-mvc,asp.net-mvc-3,entity-framework,entity-framework-4.1

The easiest way is to work out some condition that qualifies the object as "non-null", i.e. the user entered something for it, so it should be saved. Then, remove any items from the list on POST that are "null". agenttransmission.ClearingHousePartners .Where(m => string.IsNullOrWhitespace(m.ClearingHouseName)) .Remove(); That will remove any items from...

Build expression tree for LINQ using List.Contains method

c#,linq,linq-to-entities,entity-framework-4.1

You can create your own extension method, name it Where, accept an IQueryable<T>, return an IQueryable<T>, and otherwise make it emulate the form of LINQ methods. It wouldn't be a LINQ method, but it would look like one. I would discourage you from writing such a method simply because...

Storing Username to CreatedBy or UpdatedBy DB columns in Entity Framework 4.1

asp.net-mvc,asp.net-mvc-3,entity-framework,entity-framework-4.1

Use ObjectContext.SavingChanges event for this purpose. Handle entities being saved context.ObjectStateManager.GetObjectStateEntries(EntityState.Added | EntityState.Modified) and set your CreatedBy and UpdatedBy column values. http://msdn.microsoft.com/en-us/library/cc716714.aspx If you are working with DbContext, use following code to retrieve ObjectContext from it: var adapter = (IObjectContextAdapter)dbContext; var objectContext = adapter.ObjectContext; ...