entity-framework-4.1

Wrapping DbSet<TEntity> with a custom DbSet/IDbSet?

僤鯓⒐⒋嵵緔 提交于 2019-11-29 22:27:47
First off, I think this is somewhat ridiculous to do but the other members of my team insist upon it and I can't come up with a good argument against it other than "I think it's dumb"... What we're trying to do is create a completely abstract data layer and then have various implementations of that data layer. Simple enough, right? Enter Entity Framework 4.1... Our end goal here is that the programmers (I do my best to stay only on the data layer) never want to have to be exposed to the concrete classes. They only ever want to have to use interfaces in their code, aside from obviously needing

Best way to handle concurrency with entity framework

陌路散爱 提交于 2019-11-29 21:54:54
I am using entity framework 4.1.What is the best way to handle concurrency with entity framework. Is there inbuilt functionality to handle it in entity framework? Can I do without adding extra column to the tables to keep row version? Have you seen this tutorial: http://www.asp.net/entity-framework/tutorials/handling-concurrency-with-the-entity-framework-in-an-asp-net-mvc-application You can do it without a rowversion column but that often requires storing a lot of state, which can adversely affect performance. You can set up a column in your tables named RowVersion and tell Entity Framework

Entity Framework EF4.1 - stored procedure “could not be found in the container”

余生长醉 提交于 2019-11-29 19:56:22
问题 I have a SP in my database. For EF4.1, using the DbContext API. After importing the function from the data model, references to the stored procedure works fine in my development environment. But when published to the server, it fails with a message like: The FunctionImport 'SqlSearch' could not be found in the container 'TallyJ2Entities'. All other data access is working fine. It seems that in production, some aspects of the EF4 configuration are forgotten. The databases are identical, and

Updating my EF model to use 4.1 when I built it in 4.0

China☆狼群 提交于 2019-11-29 19:52:20
问题 I built my EF Model in EF 4.0, and then installed the 4.1 upgrade that includes the new DBContext interface. How do I update my model so that it uses the 4.1 features going forward? Thank You 回答1: You can use DbContext with your EDMX model. After installing EFv4.1 you should have new T4 template available: DbContext generator. This will take your EDMX and create context derived from DbContext and all POCO entities for you. Here you have walkthrough. But if you want to switch to DbContext just

Should a Repository return IEnumerable<T> , IQueryable<T> or List<T>?

随声附和 提交于 2019-11-29 16:56:24
问题 I'd like to make my application as flexible as possible, but not dig myself into a hole by making my Interface too specific. What is the best object type for a repository? IEnumerable, IQueryable, or List? The technologies I'm considering using are Azure App Fabric Caching Entity Framework 4.1 Possibly Windows Server AppFabric 回答1: I would say build your DAL using IQueryable, and pass it around, make sure your object contects lifetime is the request. This way you will get benefit of delayed

Linq to Entities (EF 4.1): How to do a SQL LIKE with a wildcard in the middle ( '%term%term%')?

﹥>﹥吖頭↗ 提交于 2019-11-29 16:45:01
问题 I want to search for this: Post Cereal and get this: Post Honey Nut Cereal where the wild cards would be the spaces. I know I could do a SPLIT and a series of ANDs and Contains() and translation to a Linq Expression for each term as a specification object, but isn't there a way to honor wildcards in the term sent to SQL? I looked at SQL functions where it's in Linq to SQL, but I am not sure what it is in Linq to Entities. I would like to do something like this: term = '%' + term.Replace(' ',

Model binding in the controller when form is posted - navigation properties are not loaded automatically

陌路散爱 提交于 2019-11-29 15:53:47
I'm using the Entity Framework version 4.2. There are two classes in my small test app: public class TestParent { public int TestParentID { get; set; } public string Name { get; set; } public string Comment { get; set; } public virtual ICollection<TestChild> TestChildren { get; set; } } public class TestChild { public int TestChildID { get; set; } public int TestParentID { get; set; } public string Name { get; set; } public string Comment { get; set; } public virtual TestParent TestParent { get; set; } } Populating objects with data from the database works well. So I can use testParent

Cannot seem to moq EF CodeFirst 4.1.Help anyone?

走远了吗. 提交于 2019-11-29 15:43:46
问题 I have been given the task to evaluate codeFirst and possible to use for all our future projects. The evaluation is based on using codeFirst with an existing database. Wondering if it's possible to mock the repository using codeFirst 4.1.(no fakes) The idea is to inject a repository into a service and moq the repository. I have been looking on the net but I have only found an example using fakes.I dont want to use fakes I want to use moq. I think my problem is in the architecture of the DAL.

How can l use Entity Framework without App.config

白昼怎懂夜的黑 提交于 2019-11-29 15:10:00
I want to use Entity Framework without app.config file. I want to define a string variable Connection String in my code and use that to connect to the database. Please show me the way if it is possible. marc_s You're not mentioning what approach you're using (database-first, model-first, code-first) - but basically, in the end, you need to define a string variable and assign it a valid EF connection string string myConnectionString = "...(define a valid EF connection string here)......"; Example for database-first approach: string myConnectionString = @"metadata=.\Model1.csdl|.\Model1.ssdl|.

Include with projection does not work

穿精又带淫゛_ 提交于 2019-11-29 14:55:11
I have this query var test = context.Assignments .Include(a => a.Customer) .Include(a => a.Subscriptions) .Select(a => new AssignmentWithSubscriptionCount { SubscriptionCount = a.Subscriptions.Count(), Assignment = a }) .ToList(); var name = test.First().Assignment.Customer.Name; It failes to eagerly load Customer, I've seen similar problems here on stackoverflow and it looks like you cant use projections with include. But I have not found a solution to my problem.. Anyone? edit: Here is a eager load with projection that work, its more complex than the example above so I cant for my life