entity framework 5 MaxLength

前端 未结 4 1541
灰色年华
灰色年华 2020-12-28 17:47

I was using EF4 and a piece of code I found to get the MaxLength value from an entity like this:

public static int? GetMaxLength(string entityTy         


        
4条回答
  •  攒了一身酷
    2020-12-28 18:37

    It means that you have not only upgraded EF but you have also changes the API. There are two APIs - the core ObjectContext API and simplified DbContext API. Your code is dependent on ObjectContext API (the only API available in EF4) but EF5 uses DbContext API (added in separate EntityFramework.dll assembly since EF4.1). If you want to use new EF features and your previous code you should just upgrade to .NET 4.5.

    If you also want to use a new API you will have to update a lot of your existing code but it is still possible to get ObjectContext from DbContext and make your method work again. You just need to use this snippet:

    var objectContext = ((IObjectContextAdapter)context).ObjectContext;
    

    and use objectContext instead of context in your code.

提交回复
热议问题