首页 \ 问答 \ ASP.Net实体框架(ASP.Net Entity Framework)

ASP.Net实体框架(ASP.Net Entity Framework)

我只是尝试使用ASP.Net实体框架,这是我第一次尝试使用ORM框架,因此忍受着我如果我吠叫错误的树。

为了简化这个问题,我得到了以下两张表格

日历

CalendarID用户标识日期事件名称

用户

UserId用户名

我已经将它们添加到我的实体框架模型中,并建立了表之间的链接。 然后,我可以通过使用类似的东西来显示我的MVC视图中的日历列表

  • <%= calendarEntry.DateAdded%>
  • 但是,如果我然后尝试使用

  • > <%= calendarEntry.Users.Username%>:<%= calendarEntry.DataAdded%>

    它调用了calendarEntry.Users,因为它说它是空的。 为什么实体框架不通过使用细节? 我需要在模型设计器中更改某些内容吗?

    如果它有助于将数据发送到视图的MVC控制器中的代码就像这样

    var Entities = new UnityGamersEntities(); 返回查看(Entities.Calendar);

    真的希望这是有道理的。


  • I'm just trying the ASP.Net Entity framework its the first time I've tried to use an ORM framework so bear with me If I'm barking up the wrong tree.

    To simplify the problem I've got the following 2 tables

    Calendar

    CalendarID UserID Date EventName

    Users

    UserId Username

    I've added them both to my Entity Framework model and its established the link between the tables. I'm able to then display a list of Calendars from my MVC view, by using something like

  • <%= calendarEntry.DateAdded%>
  • However if I then try to use

  • ><%= calendarEntry.Users.Username%> : <%= calendarEntry.DataAdded%>

    It falls over on the call to calendarEntry.Users as it says it is null. Why is the entity framework not pulling through the use details? Do I need to change something in my model designer?

    If it helps the code in the MVC controller that sends the data to the view is like this

    var Entities = new UnityGamersEntities(); return View(Entities.Calendar);

    Really hope that makes sense.


  • 原文:https://stackoverflow.com/questions/551549
    更新时间:2022-08-20 20:08

    最满意答案

    正如@ThiefMaster所提到的,您可以使用进程模块 ,它提供poll (检查进程是否终止)和communicate方法(将数据发送到子进程stdin)。

    这些方面的东西:

    # Starts encoding in a subprocess
    proc = subprocess.Popen(['ffmpeg', '-i' 'myinput', 'myoutput'])
    
    duration = 3
    sleeptime = 0
    while proc.poll() is None and sleeptime < 3: 
        # Wait for the specific duration or for the process to finish
        sleep(1)
        sleeptime += 1
    
    # If process is not terminated
    if proc.poll() is None:
        # Cancels process, waits for it to complete
        proc.communicate("q")
    

    如果尚未在指定的duration内完成,则将取消子进程。


    As @ThiefMaster mentioned, you can use the subprocess module, which provides both poll (to check whether the process is terminated) and a communicate method (to send data to the subprocess stdin).

    Something along these lines:

    # Starts encoding in a subprocess
    proc = subprocess.Popen(['ffmpeg', '-i' 'myinput', 'myoutput'])
    
    duration = 3
    sleeptime = 0
    while proc.poll() is None and sleeptime < 3: 
        # Wait for the specific duration or for the process to finish
        sleep(1)
        sleeptime += 1
    
    # If process is not terminated
    if proc.poll() is None:
        # Cancels process, waits for it to complete
        proc.communicate("q")
    

    Will cancel the subprocess if it has not finished within the specified duration.

    相关问答

    更多

    相关文章

    更多

    最新问答

    更多
  • sp_updatestats是否导致SQL Server 2005中无法访问表?(Does sp_updatestats cause tables to be inaccessible in SQL Server 2005?)
  • 如何创建一个可以与持续运行的服务交互的CLI,类似于MySQL的shell?(How to create a CLI that can interact with a continuously running service, similar to MySQL's shell?)
  • AESGCM解密失败的MAC(AESGCM decryption failing with MAC)
  • Zurb Foundation 4 - 嵌套网格对齐问题(Zurb Foundation 4 - Nested grid alignment issues)
  • 湖北京山哪里有修平板计算机的
  • SimplePie问题(SimplePie Problem)
  • 在不同的任务中,我们可以同时使用多少“上下文”?(How many 'context' we can use at a time simultaneously in different tasks?)
  • HTML / Javascript:从子目录启用文件夹访问(HTML/Javascript: Enabling folder access from a subdirectory)
  • 为什么我会收到链接错误?(Why do I get a linker error?)
  • 如何正确定义析构函数(How to properly define destructor)
  • 垂直切换菜单打开第3级父级。(Vertical toggle menu 3rd level parent stay opened. jQuery)
  • 类型不匹配 - JavaScript(Type mismatch - JavaScript)
  • 为什么当我将模型传递给我的.Net MVC 4控制器操作时,它坚持在部分更新中使用它?(Why is it that when I pass a Model to my .Net MVC 4 Controller Action it insists on using it in the Partial Update?)
  • 在使用熊猫和statsmodels时拉取变量名称(Pulling variable names when using pandas and statsmodels)
  • 如何开启mysql计划事件
  • 检查数组的总和是否大于最大数,反之亦然javascript(checking if sum of array is greater than max number and vice versa javascript)
  • 使用OpenGL ES绘制轮廓(Drawing Outline with OpenGL ES)
  • java日历格式(java Calendar format)
  • Python PANDAS:将pandas / numpy转换为dask数据框/数组(Python PANDAS: Converting from pandas/numpy to dask dataframe/array)
  • 如何搜索附加在elasticsearch索引中的文档的内容(How to search a content of a document attached in elasticsearch index)
  • LinQ to Entities:做相反的查询(LinQ to Entities: Doing the opposite query)
  • 从ExtJs 4.1商店中删除记录时会触发哪些事件(Which events get fired when a record is removed from ExtJs 4.1 store)
  • 运行javascript后如何截取网页截图[关闭](How to take screenshot of a webpage after running javascript [closed])
  • 如何使用GlassFish打印完整的堆栈跟踪?(How can I print the full stack trace with GlassFish?)
  • 如何获取某个exe应用程序的出站HTTP请求?(how to get the outbound HTTP request of a certain exe application?)
  • 嗨,Android重叠背景片段和膨胀异常(Hi, Android overlapping background fragment and inflate exception)
  • Assimp详细说明typedef(Assimp elaborated type refers to typedef)
  • 初始化继承类中不同对象的列表(initialize list of different objects in inherited class)
  • 使用jquery ajax在gridview行中保存星级评分(Save star rating in a gridview row using jquery ajax)
  • Geoxml3 groundOverlay zIndex(Geoxml3 groundOverlay zIndex)