Is it possible to use Entity Framework 6 with the first code template and write models in C # and in IronPython?
The background is that several standard models are defined in the C # core, and some specific models must be defined in IronPython.
EDIT
Custom models have been defined in our productive systems for customization. Models must be loaded and added to the DbContext when the application starts. Each model is a single IronPython file / module and will be loaded from the database (like all other scripts).
Sample not working
Program.cs
using IronPython.Hosting; using Microsoft.Scripting.Hosting; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace IronPython_EF { class Program {
SampleContext.cs
namespace IronPython_EF { using System; using System.Data.Entity; using System.Linq; public class SampleContext : DbContext { public SampleContext() : base("name=SampleContext") { } } }
User.Py
# ----------------------------------------------- # Containing the UserModel # ----------------------------------------------- # ----------------------------------------------- # Import from System import Console # ----------------------------------------------- # class User(object): userId = 0 userName = "" def __init__(self): pass def get_userId(self): return self.userId; def set_userId(self, value): self.userId = value def get_userName(self): return self.userName; def set_userId(self, value): self.userName = value UserId = property(get_userId, set_userId) UserName = property(get_userName, set_userId)
Demo.py
# ----------------------------------------------- # Demo Python Script, executing something in the # Sample-DB-Context # ----------------------------------------------- # ----------------------------------------------- # Import from System import Console # ----------------------------------------------- # Console.WriteLine("Executing demo.py") # Add User-Model userSet = DBContext.Set[User]() # Add User instance usr = User() usr.UserName = "Hallo Welt" userSet.Add(usr) # Save changes DBContext.SaveChanges()
I get an exception that User not part of DBContext.
Thank you for your help!
source share