entity-framework-4

SQL CE 4 System.Transaction support

跟風遠走 提交于 2019-12-12 16:57:21
问题 A similar question was asked here but had no answer. I am attempting to use a System.Transactions.CommittableTransaction with EF CTP4 and SQL CE 4. I have created the following transaction attribute for my ASP.NET MVC Controller actions: public class TransactionAttribute : ActionFilterAttribute { CommittableTransaction transaction; public override void OnActionExecuting(ActionExecutingContext filterContext) { transaction = new CommittableTransaction(); Transaction.Current = transaction; base

Entity Framework 4 and Synonyms

↘锁芯ラ 提交于 2019-12-12 12:35:06
问题 If, in Database A, there exists a table named "MyTable" that actually comes from a synonym pointing to another database (B), can I create this table as an entity in an Entity Framework model that represents database A, since it actually resides in a different database? I'm curious if the situation with EF 4 has improved since this: http://social.msdn.microsoft.com/Forums/en-US/adodotnetentityframework/thread/fff1067a-650d-4b47-a4e8-79eedebe5c11/ Thanks. 回答1: The answer is no, it is not

ObjectContext.SaveChanges() fails with SQL CE

 ̄綄美尐妖づ 提交于 2019-12-12 12:16:01
问题 I am creating a model-first Entity Framework 4 app that uses SQL CE as its data store. All is well until I call ObjectContext.SaveChanges() to save changes to the entities in the model. At that point, SaveChanges() throws a System.Data.UpdateException, with an inner exception message that reads as follows: Server-generated keys and server-generated values are not supported by SQL Server Compact. I am completely puzzled by this message. Any idea what is going on and how to fix it? Thanks. Here

Why is my DbModelBuilder configuration ignored when mapping Entity from DbSet<T>.SqlQuery?

谁都会走 提交于 2019-12-12 12:07:50
问题 I have a DbModel configuration like so: modelBuilder.Entity<WishlistLine>() .HasKey(w => w.PersistenceKey) .Property(w => w.PersistenceKey) .HasColumnName("WishlistLineId"); I have a query run via the following two methods: public IEnumerable<WishlistLine> FetchWishlistLinesUsingLogonName(string logonName) { return GetFromRawSql(@" SELECT wl.* FROM WishlistLines wl INNER JOIN Accounts a ON wl.AccountId = a.AccountId LEFT JOIN Users u ON u.AccountId = a.AccountId WHERE u.LogonName = @p0",

DbFunction “cannot be translated into a LINQ to Entities store expression”

北城以北 提交于 2019-12-12 12:05:42
问题 I'm trying to access database funciton using linq to sql. Herer is my SQL Scalar Function: CREATE FUNCTION Echo(@text NVARCHAR(MAX)) RETURNS NVARCHAR(MAX) AS BEGIN RETURN @text; END; I created a class called EntityFunction to call Functions in Sql Server: public static class EntityFunctions { [DbFunction("SqlServer", "Echo")] public static string Echo(string parameter) { throw new NotImplementedException(); } } And here is my DbContext: public class MainDbContext : DbContext { #region

Why does Database First EF skip mapping some tables?

给你一囗甜甜゛ 提交于 2019-12-12 11:31:02
问题 I'm using Entity Framework 4 and with a Database First binding, and EF is not generating the entities for a few of my tables. I'm not getting any errors, and no matter how many times I select the tables to generate from the "Update Model from Database" popup menu on the design surface, the same tables are still missing from the model. I get no errors in the wizard. They just don't get generated. Any clues? 回答1: EF requires a primary key on the table. EF will not map tables for which it can't

Entity Framework appending '1' to property name when it matches entity name

北慕城南 提交于 2019-12-12 11:22:29
问题 I am using Entity Framework version 4.0 to create a model using the database first approach. In the database, there's a number of tables that contain columns named the same as their parent table. So for example we have table State with columns State and StateName table Status with columns Status and Description The issue is that when one of these tables is imported into the EF model, the property names that those columns get mapped to get a '1' appended to the end of them. So I end up with

Entity Framework 4.0 - Generate change script

早过忘川 提交于 2019-12-12 11:17:36
问题 I have build my application using EF 4.0 (MS SQL 2008) and the model is getting bigger. My problem is when I add new tables / constraints etc. to the model, I'll uptil now generate a script to create my SQL database, But it drops all tables, so I loose all data. :-( Does anyone know how to just generate a change script, so I can keep data and just update the database? Thanks in advance. Søren 回答1: If you have an instance of both the existing and new databases on-hand, you can try Redgate SQL

Add Function Import not available for function

血红的双手。 提交于 2019-12-12 11:12:12
问题 I've added a function in my database and I wanted it to be callable in my code. For stored procedures I've right clicked on the SP and selected Add Function Import in Model Browser to achieve this, but this option is not available for my function. What can I do to import the function? 回答1: Database functions are not available for Function import. Function import works only with stored procedures. You must manually create stub function and mark it with EdmFunction attribute for database

Entity Framework Error: Could not find the conceptual model type for X

我的梦境 提交于 2019-12-12 11:04:02
问题 I have a demo project with two folders: Data /DbContext /EntityFramework Both have an EDMX, and for the DbContext folder, I have a DbContext generator T4 template setup. Whenever I try to run my DbContext samples, I get an error saying "Could not find the conceptual model type for X", that it can't load the metadata for an entity defined in the EntityFramework folder's EDMX... Why in the world would it do that? I did not setup any T4 template for the EDMX in the EntityFramework folder, and