entity-framework-5

Entity Framework : Set MySQL custom environment variables

可紊 提交于 2019-12-24 22:32:21
问题 I have an issue with Entity Framework 5.0. I'm working with Silverlight 5 and MySQL 5.6 too. I need to set an environment MySQL variable before each connexion to the MySQL server. E.g SET @my_var = 'test'; Under Mysql I don't have any issues. The following raises an EntityFrameworkException (syntax error near '@'). this.ObjectContext.CreateQuery<object>(" SET @my_var = 'test' "); OR this.ObjectContext.CreateQuery<object>(" CALL set_my_var('test') "); This last method raises a MySQLException

EF5 update disconnected graph (n-tier) one-to-many

旧街凉风 提交于 2019-12-24 15:52:31
问题 Problem: insert / update entity related to a parent with a one-to-many relationship in a disconnected graph scenario . UPDATE I found that the problem is just with new UserProfile I add to Brewery, the first insert is done successfully (= EF sees the relationship and creates the correct insert statement) exec sp_executesql N'insert [dbo].[BreweryUserProfiles]([BreweryId], [UserId]) values (@0, @1) ',N'@0 int,@1 int',@0=12,@1=3 No way till now to have the update working. --- The parent entity

Dynamic Expression Casting DateTime as timestamp

最后都变了- 提交于 2019-12-24 15:05:39
问题 When running a raw linq statement against entities with entity framework 5 - db2400 database, this where clause is rendered as good SQL and executes as needed: where entity.Number == stringNumber && entity.EffectiveDate == effectiveDate Rendered SQL Clause: WHERE (Filter1.NUMBER = @p__linq__0) AND (Filter1.EFFECTIVE_DATE = @p__linq__1)} However, when dynamically generating an expression with this same DateTime comparison, the SQL is sent to the DB2400 as a string casted timestamp. And DB2

Loop over entity column mappings to transform column name

一个人想着一个人 提交于 2019-12-24 14:55:19
问题 I would like to apply a single transformation over a large number of columns in Entity Framework 5 without having to explicitly type them all out. As an example I would like to do the following over 50+ columns (convert PascalCase to UNDERSCORE_CASE). modelBuilder.Entity<Department>() .Property(t => t.DepartmentName) .HasColumnName("DEPARTMENT_NAME"); I found the Dapper.FluentMap which can provide this functionality but it doesn't appear to work when creating the query. Is there a way to loop

how does Breeze saves empty strings

只愿长相守 提交于 2019-12-24 14:24:46
问题 I am retrieving an entity from the database with some proprieties. One of the proprieties is not allowed to be not null string in the database. Even though is not null it can be an empty string "" . In the EF mappings the propriety is validated like: this.Property(t => t.ColumnName) .IsRequired() .HasMaxLength(50); The problem is that when I am trying to save the changes with Breeze it returns an error for the elements that have the propriety ColumnName equal to an empty string.(saying

EntityType 'Breed' has no key defined. Define the key for this EntityType

亡梦爱人 提交于 2019-12-24 14:18:07
问题 It may looks like a copy of already asked question. i have checked all the solutions but my problem is non-logical. public class Breed { [Key] [DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)] int id { get; set; } string name { get; set; } } Error Kamdhenu.Models.Breed: : EntityType 'Breed' has no key defined. Define the key for this EntityType. Breeds: EntityType: EntitySet 'Breeds' is based on type 'Breed' that has no keys defined. 回答1: Define the properties as public . Without

Entity Framework 5 partial classes not working

谁都会走 提交于 2019-12-24 11:44:32
问题 I am using EF 5 and I have generated my model from a database. I then want to create some partial classes to extend the functionality of the EF generated classes. In EF 4 I used to simply be able to Put the namespace of the I wanted to use for these classes in to the "Custom Tool Namespace" property of the edmx file. However in EF 5 this seems to be ignored. No matter what I put in the "Custom Tool Namespace" it just keeps generating the the EF classes in the default namespace! I can

Entity framework performance tuning

限于喜欢 提交于 2019-12-24 11:35:10
问题 We are using entity framework to query a SQL server database. The LINQ expression is IQueryable. This query takes about 10 seconds to execute. If this were in a stored procedure, I would play around with the query to make it more efficient. However if I am using IQueryable, does entity framework itself decide on how to build an efficient query or do I have to play around with the linq expression and improve performance with trial and error? 回答1: does entity framework itself decide on how to

Entity Framework with Proxy Creation and Lazy Loading disabled is still loading child objects

青春壹個敷衍的年華 提交于 2019-12-24 10:58:28
问题 I'm having some issues with the Entity Framework using POCOs and I hope someone can tell me at a high level if the behaviour I'm seeing is expected or I need to dig deeper into why it's happening. I have a class Customer and another CustomerType , so Customer has a property Type (of type CustomerType indicating the type) and CustomerType has property Customers which is a collection of Customer s (All Customer s that have that type) So these are basically the Navigation properties on both ends

DropColumn conditionally in a migration

ⅰ亾dé卋堺 提交于 2019-12-24 03:12:48
问题 I want to perform a column dropping in my Up migration. I am using EF 5. DropColumn("dbo.MyObjects", "AttributeId"); The issue is that in some way part of database instances do not have that column (long story how). I am thinking of dropping it with Sql and searching in sys.columns , or wrapping DropColumn in try ... catch . But maybe there is some known way to do it with Entity Framework migrations? 回答1: There was also a default constraint on my column, so ended up with the following: public