entity-framework-4

EF Pre Compile query and return of a scalar value

元气小坏坏 提交于 2019-12-12 01:49:39
问题 I use asp.net 4 c# and ef4. I have this code, it should compile a query and return a single scalar value (I use anonymous type). My code does not have apparently errors, but because is the first time I write a compiled query I would like to know if is well written or could be improved for a performance boost. var query = CompiledQuery.Compile((CmsConnectionStringEntityDataModel ctx) => from o in ctx.CmsOptions where o.OptionId == 7 select new { Value = o.Value }); uxHtmlHead.Text = query

Entity Framework CTP 5 RelatedTo Attribute not working

﹥>﹥吖頭↗ 提交于 2019-12-12 01:48:22
问题 Using Entity Framework CTP 5 I am trying to make a list of foreign keys in my class. But I keep getting an error which says RelatedTo can not be found. Here is the code: public class VertragsVerweis : GenericBLL { [Key] public String Uid { get; set; } public String VertagsVerweisNr { get; set; } public String Bezeichnung { get; set; } public Boolean Reparatur { get; set; } [RelatedTo(RelatedProperty="Artikel")] public List<Artikel> Artikelen { get; set; } } This gives me the error: Error 2

How to load the related entities using Entity Framework and the Repository Pattern

♀尐吖头ヾ 提交于 2019-12-12 01:46:18
问题 This question is related to this I have decided to change the Generic Repository pattern and used a specific repository for each entity. However I just cant find how to make it work because in my html I need to show some fields from related entities. Is it better to replace Ienumerable with Iqueryable? Repository Interface public interface IApplicantPositionRepository : IDisposable { IEnumerable<ApplicationPositionHistory> GetApplicationPositionHistories(int applicantId, int positionId); void

DataGridViewComboBoxColumn not taking ValueMember

狂风中的少年 提交于 2019-12-12 01:11:54
问题 I have a Many to Many mixed with some Master-Detail DataGrid setup. 4 DataGridView 6 Entities (2 mapping tables) 5 Data relations To give you a visual image, there is 1 big Employe DGV (DataGridView), and 3 smaller ones which updates depending on the Employe DGV selected row. One of the 3 smaller grid is a really simple relation without a mapping table. The other 2, however, displays a mapping table rows that uses formatedinfo of the entity it is mapping to. Those 2 DGV only have 1 column, a

Dynamic table name in entity framework linq

≡放荡痞女 提交于 2019-12-12 00:50:50
问题 I am currently using entity framework (.net 4) to read from a 3rd party database using LINQ statements. Unfortunately, at compile time i do not know from which table i will be reading - in fact, new tables can be added to this database after my application is compiled. The table name to read from will be passed as a string parameter to my method. How should one approach this situation when the table name is not know at compile time? i cannot even add these tables to my data model since they

Can a Entity Framework Trackable collection be bound to an ASP.Net Gridview?

故事扮演 提交于 2019-12-11 23:55:56
问题 I've got a GridView on a ASP.Net page. I would like to set the DataSource of the Gridview to a trackable collection of Entity Framework objects. I though the code should look like this: this.gvMyGridView.DataSource = entity.MyDetailedItems; this.gvMyGridView.DataBind(); But this doesn't display any data. I am using self tracking entities and the MyDetailedItems is a navigation property to rows from another table. 回答1: EF 4 with self tracking entities does not support lazy loading so you must

Cache table with Entity Framework 4

為{幸葍}努か 提交于 2019-12-11 23:45:23
问题 I have a table with a lot of rows that is the products table, when an user searches the website, I make a select from this table and I also use the Include method in the select, I used profiler and I noticed that EF generates a query with a lot of inner joins, left joins etc. What I wanted to do is to use this select query and insert the result in a temporary cache table in the same database and then I can create a service to update this table every x minutes. The problem is, how do I make EF

Change table name at runtime using Entity Framework 4

ε祈祈猫儿з 提交于 2019-12-11 23:23:38
问题 Is it possible to change the name of the table a specific entity is mapped to in Entity Framework 4 (model first)? I need to create one model per customer and thus need to prefix the table names. Maybe simpler to use one database per customer. What is the best practice? 回答1: Use database per customer. Databases must have same schema. Modifying mapping at runtime is not a good idea. Edit: Model per customer means EDMX per customer. Be aware that metadata are shared. So in multi-tenant

Sharing Entity framework objects across projects?

喜你入骨 提交于 2019-12-11 22:07:28
问题 I am having some refactor troubles, maybe someone knows why... In one solution I have a WCF service. In another solution I have a RIA application. Since the SQL database between these two is identical, I wanted to create a separate project, in which to host the edmx file as well as a domain service. If I create the edmx file in the WCF project directly, and do the same on the RIA side, everything works fine. But when I try to pull this edmx file into a separate project and add references to

Get EntityFramework Added entities as gridview datasource

无人久伴 提交于 2019-12-11 19:27:16
问题 In EntityFramework 4, which is the correct way to get entities from: - the database (minus the Deleted objects), - and in-memory Added ones to show them in a GridView ? Using linq to entities I get the data currently in database. Using ObjectStateManager.GetObjectStateEntries(entityState).Select(ent => ent.Entity).OfType<IEntityWithKey>() , I get the Added and/or Deleted (as desired) With linq to entities I'm getting the Deleted objects in the query result, so they are shown in the gridvew