entity-framework-4

Get Custom Attributes applied to generated entities via MetadataType attribute

萝らか妹 提交于 2019-12-07 03:19:40
问题 In our application, we are using EF4.0 and POCO Entity generator to generate Entities from the database. To apply data annotation, we are creating Interfaces and implementing those interfaces on the partial classes we have created to match the partial class generated by using EF. /*Entity Generated Type*/ public partial class SomeEntity : EntityBase { public virtual string SomeProperty { get {...} set {...} } } /*Interface containing metadata*/ public interface ISomeEntityMetadata {

How can I override SQL scripts generated by MigratorScriptingDecorator

南楼画角 提交于 2019-12-07 03:19:17
问题 Using Entity Framework 4.3.1 Code first, and Data Migrations. I have written a utility to automatically generate the Migration scripts for a target database, using the MigratorScriptingDecorator. However, sometimes when re-generating the target database from scratch, the generated script is invalid, in that it declares a variable with the same name twice. The variable name is @var0 . This appears to happen when there are multiple migrations being applied, and when at least two result in a

Where is modelBuilder.IncludeMetadataInDatabase in EF CTP5?

…衆ロ難τιáo~ 提交于 2019-12-07 02:38:21
问题 With CTP4, I used to be able to do the following (as suggested by ptrandem): modelBuilder.IncludeMetadataInDatabase = false With this line of code, EF doesn't create the EdmMetadata table in my database, and doesn't track model changes. I was unable to find a way to accomplish this in the new CTP5, so now every time I change my model, I get this: The model backing the 'MyContext' context has changed since the database was created. Either manually delete/update the database, or call Database

Using IQueryable<TEntity> instead DbSet<TEntity> problem

 ̄綄美尐妖づ 提交于 2019-12-07 02:22:38
问题 i stumbled to the next problem... I have database context: // For support unit testing... public interface IDbContext : IDisposable { IQueryable<Hardware> Hardwares { get; } IQueryable<ProviderHardware> ProviderHardwares { get; } } // Real DbContext (EF 4.0, Code First) public class PrimaryDbContext : DbContext, IDbContext { public DbSet<Hardware> Hardwares { get; set; } public DbSet<ProviderHardware> ProviderHardwares { get; set; } IQueryable<Hardware> IDbContext.Hardwares { get { return

Create new EF object with foreign key reference without loading whole rereference object

雨燕双飞 提交于 2019-12-07 01:52:34
问题 I want to create a new EF object which references another object (the aspnet userId in my example) without loading the foreign (key) object. So essentially I want to do the following: buskerSet bs = new buskerSet(); bs.Title = title; bs.Image = image; bs.Created = DateTime.Now; //The following will crash, because bs.aspnet_Users is null bs.aspnet_Users.UserId = userId; context.SaveChanges(); In the bs.aspnet_UsersReference I can't find anything that would help.. SOLUTION: aspnet_Users user =

What is the best way of using DTOs in a SOA application?

家住魔仙堡 提交于 2019-12-07 01:07:51
问题 We are implementing a SOA web application using EF, WCF and jQuery. Here is our architecture in a brief view: ------------- --- | UI | | | ------------- | | | Services | | D | ------------- | T | | Businsess | | O | ------------- | | | Dal | | | ------------- --- We know that we should have DTO classes to pass data between the layers specially between the Services and the UI but We have some conceptual issues about the way of using DTOs (to send to the UI or receive from UI). For Data-Driven

View EF4 generated queries?

℡╲_俬逩灬. 提交于 2019-12-07 01:02:26
LINQ-to-SQL had several ways, including a visualizer add-in, to view the generated SQL from an IQueryable. I can't find the equivalent for Entity Framework 4. Nothing on StackOverflow, no blogs. How is it done? Preferably, I'd like to be able to do it in code and without having to actually execute the query just to see it. Thanks! there are several approaches to looking at the sql. Free On the ObjectQuery do .ToTraceString() that will show u the sql generated for the query. Download ef tracing provider written by one of the EF team members. E F Tracing Provider Linq To Entities visualizer

Is SaveChanges() Necessary with Function Imports (Stored Procedures)?

会有一股神秘感。 提交于 2019-12-06 21:08:09
问题 Is SaveChanges() necessary with function imports (stored procedures)? Example: void foo(Product product) { // AddProduct is a function import of a stored procedure entities.AddProduct(product.Name, product.Price, product.Description); entities.SaveChanges(); // Is this necessary? } 回答1: According to MSDN, SaveChanges Persists all updates to the data source and resets change tracking in the object context. That is, for any entities that are attached to the context and which you have added,

Cannot resolve Symbol ObjectStateManager

北城余情 提交于 2019-12-06 20:14:38
问题 I have getting an Error of " Cannot Resolve Symbol ObjectStateManager " when trying to call it on my Database context from Entity Framework 4. I can't find anyone else having this issue. I have tried using System.Data and System.Data.Objects . Is there a specific Entity Framework that needs to be made in order to use the ObjectStateManager? Or Am I missing some sort of install package? I am using Database First Entity Framework. Here is the code it is giving my error: (Line 7) [HttpPost]

Entity Framework losing Sql DateTime precision

Deadly 提交于 2019-12-06 19:56:32
问题 I am querying my EDM using Entity SQL and am losing millsecond precision on my DateTime values. For example 2011/7/20 12:55:15.333 PM gets changed to 2011/7/20 12:55:15.000 PM. I have confirmed that in SQL the milliseconds are recorded precisely. There is a Precision attribute I can apply in the .edmx XML file, but I do not know what sort of values it takes, <Property Name="Timestamp" Type="DateTime" Nullable="false" Precision="???" /> Does anyone know how to use this precision attribute ?