随笔分类 - Entity Framework
摘要:public class Foo { public IList Strings { get; set; } } class Program { static void Main(string[] args) { //Func func = // a => a.Strings.Any(b => b == "asdf"); // b => b == "asdf"; var bParameter = Expression.Parameter(...
阅读全文
摘要:public Expression<Func<Job, bool>> ToLambda() { Type type = typeof (Job); ParameterExpression parameterExpression = Expression.Parameter(type, "job"); Expression body = Expression.Equal(Expression.Property(parameterExpression, "MemberId"), Expression.Constant(MemberId
阅读全文
摘要:常见问题:无法更改关系,因为一个或多个外键属性不可以为 null。对关系作出更改后,会将相关的外键属性设置为 null 值。如果外键不支持 null 值,则必须定义新的关系,必须向外键属性分配另一个非 null 值,或必须删除无关的对象。解决方法:例如OrderItem和Product是一对多的关系OrderItem.ProductId是关系的外键你要先删除对product的引用,比如表OrderItem里有一个到Product.Id的外键的话,需要将其设为空值对应。所以在删除之前要将OrderItem.ProductId设置为0或null
阅读全文
摘要:对关系使用默认规则与配置In Chapter 3, you learned about convention and configuration that affect attributes of properties and the effects that these have on the database. In this chapter, the focus will be on convention and configuration that affects the relationships between classes. This includes how classes
阅读全文
摘要:Most of the time the Entity Framework (EF) can manage transactions for you. Every time you Add an Entity, Delete an Entity, Change an Entity, Create a Relationship or Delete a Relationship in your .NET code, these changes are remembered by the EF, and when you call SaveChanges()these are convert...
阅读全文