entity-framework

Building Project that uses EntityFramework fails with a lot of errors

无人久伴 提交于 2020-02-07 17:08:49
问题 I am using EntityFramework as my Data Access Layer in a Visual Studio C# project. I have added a new entity model and built right away without adding or doing anything to test its functionality. Unfortunately, the build failed with many errors like: CS0426 The type name 'Data' does not exist in the type 'System' CS0138 A 'using namespace' directive can only be applied to namespaces; 'System' is a type not a namespace. Consider a 'using static' directive instead CS0246 The type or namespace

Building Project that uses EntityFramework fails with a lot of errors

随声附和 提交于 2020-02-07 17:08:10
问题 I am using EntityFramework as my Data Access Layer in a Visual Studio C# project. I have added a new entity model and built right away without adding or doing anything to test its functionality. Unfortunately, the build failed with many errors like: CS0426 The type name 'Data' does not exist in the type 'System' CS0138 A 'using namespace' directive can only be applied to namespaces; 'System' is a type not a namespace. Consider a 'using static' directive instead CS0246 The type or namespace

EF Core: Eager loading (.Include) sub-categories (self-reference)

本秂侑毒 提交于 2020-02-06 10:44:34
问题 We have something like this var categories = _context.Categories.Include("Categories1.Categories1.Categories1"); That works and handles sub-categories up to 4-level deep (which is enough for now but who knows the future) Is there a better way to do it? More info We use database-first. Category table has these columns: Id ParentCategoryId <-- this has foreign key to Category.Id 回答1: In this particular case I think a recursive property might be a good bet. Trying to do this from memory (been

EF Core: Eager loading (.Include) sub-categories (self-reference)

混江龙づ霸主 提交于 2020-02-06 10:41:29
问题 We have something like this var categories = _context.Categories.Include("Categories1.Categories1.Categories1"); That works and handles sub-categories up to 4-level deep (which is enough for now but who knows the future) Is there a better way to do it? More info We use database-first. Category table has these columns: Id ParentCategoryId <-- this has foreign key to Category.Id 回答1: In this particular case I think a recursive property might be a good bet. Trying to do this from memory (been

getting an error on trying to call method in generic way

帅比萌擦擦* 提交于 2020-02-06 07:55:33
问题 Hi all I am trying to filter the table using where class by passing parameter to the method like as below, private IQueryable<SpaceFunctionType> Get<TEntity>(Expression<Func<TEntity, bool>> predicate) where TEntity : class, ICategorySpaceFunction { return _dbContext.Set<TEntity>().Where(predicate) .Select(c => new SpaceFunctionType { Category = c.Category, SpaceFunction = c.SpaceFunction }); } public IQueryable<SpaceFunctionType> GetSpaceFunctionType(string environmentSource) { return Get

Problem with save cyrillics data to sqlexpress database

和自甴很熟 提交于 2020-02-06 06:34:05
问题 I am using .net entity framework, asp.net mvc, sqlexpress and have one problem: when save data to sqlexpress database table (something like this само да пробам ) on that table I have this ???? ?? ??????. On column where insert cyrillics data I set collation:Serbian_Cyrillic_100_CI_AI. 回答1: The datatype of the column should be nvarchar (which is Unicode). 来源: https://stackoverflow.com/questions/5602049/problem-with-save-cyrillics-data-to-sqlexpress-database

Problem with save cyrillics data to sqlexpress database

拟墨画扇 提交于 2020-02-06 06:33:46
问题 I am using .net entity framework, asp.net mvc, sqlexpress and have one problem: when save data to sqlexpress database table (something like this само да пробам ) on that table I have this ???? ?? ??????. On column where insert cyrillics data I set collation:Serbian_Cyrillic_100_CI_AI. 回答1: The datatype of the column should be nvarchar (which is Unicode). 来源: https://stackoverflow.com/questions/5602049/problem-with-save-cyrillics-data-to-sqlexpress-database

Linq on EF7 doesnt work with Joins and Dates?

流过昼夜 提交于 2020-02-06 04:57:08
问题 I am having some troubles running a query from a Controller on my ASP.NET MVC6 EF7 web app... The Model and DbContext are in this previous ask: EF7 Incorrect configuration of the DBContext? The problem appears when I try to run the following Linq query which contains a couple of joins and tries to get some entries from a Database for a particular date... public IActionResult GetEntries(int year, int month, int day) { //_context.Database.SetCommandTimeout(180); string dateTest = new DateTime

How do I set a default value for a new column using EF6 migrations?

倾然丶 夕夏残阳落幕 提交于 2020-02-06 04:42:42
问题 I know that you can manually manipulate the EF generated migration file to add in the 'defaultValue: 1' parameter to the 'AddColumn' method, but it does not seem to be generating the correct Oracle translation when I look at the generated script. See my EF migration 'Up' method below: public override void Up() { AddColumn("TABLE", "NEW_COLUMN", c => c.Decimal(nullable: false, precision: 10, scale: 0, defaultValue: 1)); } And after running 'update-database -script' I get the following

ObjectContext public in debug mode, internal in release mode

折月煮酒 提交于 2020-02-06 02:51:34
问题 Is there an easy way to make an ObjectContext public in debug mode and internal in release mode? With Linqpad it is very convenient to connect to an ObjectContext for quick testing and querying, so for development purposes I want it to be public. But I don't want to think of the consequences when the same convenience is deployed to some smart customer. 回答1: As mentioned in the comment, this may not be of any practical use, but: #if DEBUG public #endif class YourContext : ObjectContext { ... }